[Linpha-cvs] SF.net SVN: linpha: [4699] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <bz...@us...> - 2007-03-18 12:22:39
|
Revision: 4699 http://svn.sourceforge.net/linpha/?rev=4699&view=rev Author: bzrudi Date: 2007-03-17 09:29:01 -0700 (Sat, 17 Mar 2007) Log Message: ----------- made PJMT work again for EXIF data and set to default as metadata tool for now... Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/install/sql/sql.data.php trunk/linpha2/lib/classes/linpha.exiftool.class.php trunk/linpha2/lib/classes/linpha.import.class.php trunk/linpha2/lib/classes/linpha.metadata.class.php trunk/linpha2/lib/classes/linpha.pjmt.class.php trunk/linpha2/lib/modules/module.search.php trunk/linpha2/templates/default/search.html.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/ChangeLog 2007-03-17 16:29:01 UTC (rev 4699) @@ -1,4 +1,11 @@ 2007-03-17 bzrudi + * PJMT is working again and the default for now, even so exiftool also works + fine for EXIF data right now. ;-) + Status: Currently EXIF should work again using PJMT and exiftool. No IPTC, + no XMP, no searching and tons of other littel bugs and + improvements left open. + +2007-03-17 bzrudi * Next step towards clean MetaData handling. Rewitten MetaData classes and tons of ot other things. Naturally most everything is broken this time. This update requires to run "reset_database.php" and will only work for @@ -14,7 +21,7 @@ will replace PJMT even for EXIF data once it's been testet. PJMT will just be available as fallback when ExifTool can't be used for some reason. Do not expect MetaData working smoothly right now, it's just dirt hacking - to get some results using ExifTool. Things will get better of the next + to get some results using ExifTool. Things will get better over the next weeks ;-) This includes rewrite of of the linpha.metadata.class.php and friends. Modified: trunk/linpha2/install/sql/sql.data.php =================================================================== --- trunk/linpha2/install/sql/sql.data.php 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/install/sql/sql.data.php 2007-03-17 16:29:01 UTC (rev 4699) @@ -36,7 +36,7 @@ 'sys_import_autoimport' => '1', 'sys_import_exif' => '1', 'sys_import_exif_autorot' => '1', - 'sys_import_use_exiftool' => '1', + 'sys_import_use_exiftool' => '0', 'sys_image_exif' => '1', 'sys_image_iptc' => '0', Modified: trunk/linpha2/lib/classes/linpha.exiftool.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.exiftool.class.php 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/lib/classes/linpha.exiftool.class.php 2007-03-17 16:29:01 UTC (rev 4699) @@ -113,7 +113,7 @@ * Save all MetaData to database * @param string $filename filename to parse for MetaData * @param string $md5sum md5sum of file - * @param string $tag save IPTC or XMP MetaData + * @param string $tag save EXIF, IPTC or XMP MetaData */ function saveMetaData($filename, $md5sum, $tag) { @@ -158,10 +158,64 @@ } } - public function getRotationByExifTag($rotation) + + /** + * Simple method to return just exif date and orientation tag during + * import as needed by linpha_photos, this is not used for any meta_x table. + * example: 2004:02:14 18:24:19 and -90 + * + * @param string $dirname, $filename + * @return array $time_exif (unix timestamp) + * $rotate (degrees to rotate) + * @author bzrudi,flo + **/ + public function getBasicMeta($dirname, $filename) { - $rotate = "0"; - return $rotate; + $return = ""; + $meta = ""; + $filename = "".$dirname."/".$filename.""; + $parameters = "-exif:datetimeoriginal " . // Get date tag + "-exif:orientation " . // Get orientation tag + "-s -n -t"; // Print tag name tab seper. + + exec("$this->exiftool $parameters $filename", $meta, $return); + + if(is_array($meta)) + { + foreach($meta AS $value) + { + $temp = explode("\t", $value); + $metaArray[strtolower(trim($temp['0']))] = @trim($temp['1']); + } + + } + + $date = $metaArray['datetimeoriginal']; + if(strlen($date) > 4) + { + $year = substr($date, 0, 4); + $month = substr($date, 5, 2); + $day = substr($date, 8, 2); + $hour = substr($date, 11, 2); + $min = substr($date, 14, 2); + $sec = substr($date, 17, 2); + $time_exif = mktime($hour, $min, $sec, $month, $day, $year); + } + else + { + $time_exif = "0"; + } + + if($metaArray['orientation']) + { + $rotate = $metaArray['orientation']; + } + else + { + $rotate = "0"; + } + + return array($time_exif, $rotate); } /** Modified: trunk/linpha2/lib/classes/linpha.import.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.import.class.php 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/lib/classes/linpha.import.class.php 2007-03-17 16:29:01 UTC (rev 4699) @@ -475,25 +475,37 @@ */ if( $GLOBALS['linpha']->sql->config->value['sys_import_exif'] ) { - include_once( LINPHA_DIR.'/lib/classes/pjmt/EXIF.php' ); + + /** + * Get EXIF date and orientation tag from image if avail + */ + list($time_exif, $rotate) = $MetaData->getBasicMeta($dirname, $filename); + + + /* + include_once( LINPHA_DIR.'/lib/classes/pjmt/EXIF.php' ); $meta = get_EXIF_JPEG($dirname.'/'.$filename); - + */ /** * get date */ + /* if( isset($meta[0][34665]['Data'][0][36867]['Data'][0]) ) { $time_exif = $MetaData->convertExifDateToUnix( $meta[0][34665]['Data'][0][36867]['Data'][0] ); } - - /** + */ + + /** * get rotate information * turn off exif autorotate using 'sys_import_exif_autorot' */ + /* if( $GLOBALS['linpha']->sql->config->value['sys_import_exif_autorot'] && isset($meta[0][274]['Data'][0]) ) { $rotate = 0; //$rotate = $MetaData->getRotationByExifTag( $meta[0][274]['Data'][0] ); } + */ } } } Modified: trunk/linpha2/lib/classes/linpha.metadata.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.metadata.class.php 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/lib/classes/linpha.metadata.class.php 2007-03-17 16:29:01 UTC (rev 4699) @@ -590,21 +590,7 @@ $this->available_fields = $this->objMetaTool->available_fields; } - - /** - * Simple wrapper method to take care of used MetaData Toolkit - * @param string $rotation - * @return string degrees to rotate - * @author bzrudi - */ - public function getRotationByExifTag($rotation) - { - $this->objMetaTool->getRotationByExifTag($rotation); - } - - - - + public function createMetaDataTable($array, $metatype) { if (!is_array($array)) @@ -695,23 +681,94 @@ } /** - * converts a exif date to a unix timestamp + * Simple wrapper method to convert an exif date to an unix timestamp + * and also return orientation tag if avail * example: 2004:02:14 18:24:19 -> 11167594589 * - * @author flo * @param string $date * @return int unix timestamp + * @author flo,bzrudi + **/ + public function getBasicMeta($dirname, $filename) + { + + list($time_exif, $rotate) = + $this->objMetaTool->getBasicMeta($dirname, $filename); + + if(isset($rotate)) + { + $rotate = $this->getRotationByExifTag($rotate); + } + return array($time_exif, $rotate); + + } + + /** + * Autorotate Images via EXIF tag + * Most Images contain an orientation tag which shows if and how to rotate + * the images + * @param int exif rotation tag + * @return degrees to rotate + * @author bzrudi */ - function convertExifDateToUnix($date) { - $year = substr($date, 0, 4); - $month = substr($date, 5, 2); - $day = substr($date, 8, 2); - $hour = substr($date, 11, 2); - $min = substr($date, 14, 2); - $sec = substr($date, 17, 2); - return mktime($hour, $min, $sec, $month, $day, $year); + protected function getRotationByExifTag($rotation) { + if(is_numeric($rotation)) { + switch ($rotation) { + //No Rotation, No Flip Row 0 is at the visual top of the + //image, and column 0 is the visual left-hand side + case "1" : + $rotate = "0"; + break; + //No Rotation, Flipped Horizontally Row 0 is at the visual + //top of the image,and column 0 is the visual right-hand side + case "2" : + $rotate = "0"; + break; + //Rotated 180 degrees, No Flip Row 0 is at the visual + //bottom of the image, and column 0 is the visual right-hand side + case "3" : + $rotate = "180"; + break; + //No Rotation, Flipped Vertically Row 0 is at the visual + //bottom of the image, and column 0 is the visual left-hand side + case "4" : + $rotate = "0"; + break; + //Flipped Horizontally, Rotated 90 degrees counter clockwise + //Row 0 is at the visual left-hand side of of the image, + //and column 0 is the visual top + case "5" : + $rotate = "0"; + break; + //No Flip, Rotated 90 degrees clockwise Row 0 is at the visual + //right-hand side of of the image, and column 0 is the visual top + case "6" : + $rotate = "90"; + break; + //Flipped Horizontally, Rotated 90 degrees clockwise Row 0 is + //at the visual right-hand side of of the image, and + //column 0 is the visual bottom + case "7" : + $rotate = "0"; + break; + //No Flip, Rotated 90 degrees counter clockwise Row 0 is at + //the visual left-hand side of of the image, and column 0 is + //the visual bottom + case "8" : + $rotate = "-90"; + break; + default : + $rotate = "0"; + break; + + } + } else // no rotation data is found, default to "0" + { + $rotate = "0"; + } + return $rotate; } -} // end class LinMetaData +} /* vi: set ts=4 sw=4 sts=4 */ ?> Modified: trunk/linpha2/lib/classes/linpha.pjmt.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.pjmt.class.php 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/lib/classes/linpha.pjmt.class.php 2007-03-17 16:29:01 UTC (rev 4699) @@ -26,14 +26,22 @@ */ class LinPjmtTool extends LinMetaData { - + /** + * Constructor + */ function __construct() { } - - public function saveMetaData($filename, $md5sum, $metatype) { + /** + * Save all MetaData to database + * @param string $filename filename to parse for MetaData + * @param string $md5sum md5sum of file + * @param string $tag save IPTC or XMP MetaData + */ + public function saveMetaData($filename, $md5sum, $metatype) + { include_once (LINPHA_DIR . '/lib/classes/pjmt/JPEG.php'); include_once (LINPHA_DIR . '/lib/classes/pjmt/EXIF.php'); @@ -44,17 +52,23 @@ * get exif info from file */ $exif_data = get_EXIF_JPEG($filename); - if ($exif_data) { + if($exif_data) + { /** * special tags */ // Canon Owner Name append to Artist - if (isset ($exif_data['Makernote_Tag']['Decoded Data']) && is_array($exif_data['Makernote_Tag']['Decoded Data']) // sometimes 'Decoded Data' is an empty string - && isset ($exif_data['Makernote_Tag']['Decoded Data'][0][9]['Text Value'])) { + if (isset ($exif_data['Makernote_Tag']['Decoded Data']) + && is_array($exif_data['Makernote_Tag']['Decoded Data']) // sometimes 'Decoded Data' is an empty string + && isset ($exif_data['Makernote_Tag']['Decoded Data'][0][9]['Text Value'])) + { $owner = $exif_data['Makernote_Tag']['Decoded Data'][0][9]['Text Value']; - if (isset ($exif_data[0][315]['Text Value'])) { + if (isset ($exif_data[0][315]['Text Value'])) + { $exif_data[0][315]['Text Value'] .= $owner; - } else { + } + else + { $exif_data[0][315]['Text Value'] = $owner; } @@ -63,33 +77,40 @@ /** * search for valid tags */ - foreach ($this->defined_fields['exif'] AS $key => $value) - //foreach(LinMetaData::$Tags['exif'] AS $key=>$value) + foreach($this->defined_fields['exif'] AS $key => $value) + { + if(!empty(LinPjmtTool::$metaTags['exif'][$key]['pathvalue'])) { - if (!empty ($objMetaTool->metaTags['exif'][$key]['pathvalue'])) { /** - * there are currently only entries at level deep 2 and 5 in the array + * there are currently only entries at level deep 2 and 5 + * in the array */ - $array_pieces = explode('/', $objMetaTool->metaTags['exif'][$key]['pathvalue']); - switch (count($array_pieces)) { + $ap = explode('/', + LinPjmtTool::$metaTags['exif'][$key]['pathvalue']); + + switch(count($ap)) + { case 2 : - if (isset ($exif_data[$array_pieces[0]][$array_pieces[1]]['Text Value'])) { + if(isset($exif_data[$ap[0]][$ap[1]]['Text Value'])) + { $str_columns .= $key . ', '; - $exif_value = $exif_data[$array_pieces[0]][$array_pieces[1]]['Text Value']; + $exif_value = $exif_data[$ap[0]][$ap[1]]['Text Value']; $str_values .= "'" . LinSql :: linAddslashes(trim($exif_value)) . "', "; } break; case 5 : - if (isset ($exif_data[$array_pieces[0]][$array_pieces[1]][$array_pieces[2]][$array_pieces[3]][$array_pieces[4]]['Text Value'])) { + if(isset ($exif_data[$ap[0]][$ap[1]][$ap[2]][$ap[3]][$ap[4]]['Text Value'])) + { $str_columns .= $key . ', '; - $exif_value = $exif_data[$array_pieces[0]][$array_pieces[1]][$array_pieces[2]][$array_pieces[3]][$array_pieces[4]]['Text Value']; + $exif_value = $exif_data[$ap[0]][$ap[1]][$ap[2]][$ap[3]][$ap[4]]['Text Value']; $str_values .= "'" . LinSql :: linAddslashes(trim($exif_value)) . "', "; } break; default : - echo "Error no valid path for key: " . $key . " value: " . $objMetaTool->metaTags['exif'][$key]['pathvalue'] . "<br />"; + echo "Error no valid path for key: " . $key . " value: " . + LinPjmtTool::$metaTags['exif'][$key]['pathvalue'] . "<br />"; break; } } @@ -98,10 +119,12 @@ /** * add jpegcomment */ - if (isset ($this->defined_fields['exif']['jpegcomment'])) { + if(isset ($this->defined_fields['exif']['jpegcomment'])) + { $jpeg_header_data = get_jpeg_header_data($filename); $comment = get_jpeg_Comment($jpeg_header_data); - if (!empty ($comment)) { + if(!empty ($comment)) + { $str_columns .= 'jpegcomment, '; $str_values .= "'" . LinSql :: linAddslashes(trim($comment)) . "', "; } @@ -114,13 +137,14 @@ $str_columns = substr($str_columns, 0, strlen($str_columns) - 2); $str_values = substr($str_values, 0, strlen($str_values) - 2); - $GLOBALS['linpha']->db->Execute("INSERT into " . LIN_PREFIX . "meta_exif (" . $str_columns . ") " . - "VALUES (" . $str_values . ")"); + $GLOBALS['linpha']->db->Execute("INSERT INTO " . LIN_PREFIX . + "meta_exif (" . $str_columns . ") " . + "VALUES (" . $str_values . ")"); } /** - * define tags to index and set available fields + * Define tags to index and set available fields * @param string $tag [exif] */ public function setMetaFields($tag) @@ -156,72 +180,57 @@ } } + /** - * Autorotate Images via EXIF tag - * Most Images contain an orientation tag which shows if and how to rotate - * the images - * @param int exif rotation tag - * @return degrees to rotate - * @author bzrudi - */ - function getRotationByExifTag($rotation) { - if (is_numeric($rotation)) { - switch ($rotation) { - //No Rotation, No Flip Row 0 is at the visual top of the - //image, and column 0 is the visual left-hand side - case "1" : - $rotate = "0"; - break; - //No Rotation, Flipped Horizontally Row 0 is at the visual - //top of the image,and column 0 is the visual right-hand side - case "2" : - $rotate = "0"; - break; - //Rotated 180 degrees, No Flip Row 0 is at the visual - //bottom of the image, and column 0 is the visual right-hand side - case "3" : - $rotate = "180"; - break; - //No Rotation, Flipped Vertically Row 0 is at the visual - //bottom of the image, and column 0 is the visual left-hand side - case "4" : - $rotate = "0"; - break; - //Flipped Horizontally, Rotated 90 degrees counter clockwise - //Row 0 is at the visual left-hand side of of the image, - //and column 0 is the visual top - case "5" : - $rotate = "0"; - break; - //No Flip, Rotated 90 degrees clockwise Row 0 is at the visual - //right-hand side of of the image, and column 0 is the visual top - case "6" : - $rotate = "90"; - break; - //Flipped Horizontally, Rotated 90 degrees clockwise Row 0 is - //at the visual right-hand side of of the image, and - //column 0 is the visual bottom - case "7" : - $rotate = "0"; - break; - //No Flip, Rotated 90 degrees counter clockwise Row 0 is at - //the visual left-hand side of of the image, and column 0 is - //the visual bottom - case "8" : - $rotate = "-90"; - break; - default : - $rotate = "0"; - break; - - } - } else // no rotation data is found, default to "0" - { - $rotate = "0"; + * Simple method to return just exif date and orientation tag during + * import as needed by linpha_photos, this is not used for any meta_x table. + * example: 2004:02:14 18:24:19 and -90 + * + * @param string $dirname, $filename + * @return array $time_exif (unix timestamp) + * $rotate (degrees to rotate) + * @author bzrudi,flo + **/ + public function getBasicMeta($dirname, $filename) + { + include_once( LINPHA_DIR.'/lib/classes/pjmt/EXIF.php' ); + $date = ""; + $meta = get_EXIF_JPEG($dirname.'/'.$filename); + + if(isset($meta[0][34665]['Data'][0][36867]['Data'][0]) ) + { + $date = $meta[0][34665]['Data'][0][36867]['Data'][0]; } - return $rotate; + + if(strlen($date) > 4) + { + $year = substr($date, 0, 4); + $month = substr($date, 5, 2); + $day = substr($date, 8, 2); + $hour = substr($date, 11, 2); + $min = substr($date, 14, 2); + $sec = substr($date, 17, 2); + $time_exif = mktime($hour, $min, $sec, $month, $day, $year); + } + else + { + $time_exif = "0"; + } + + if(isset($meta[0][274]['Data'][0])) + { + $rotate = $meta[0][274]['Data'][0]; + } + else + { + $rotate = "0"; + } + + + return array($time_exif, $rotate); + } - + /** * Define array with allowed EXIF tags and human readable translation * @param none Modified: trunk/linpha2/lib/modules/module.search.php =================================================================== --- trunk/linpha2/lib/modules/module.search.php 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/lib/modules/module.search.php 2007-03-17 16:29:01 UTC (rev 4699) @@ -245,8 +245,7 @@ /** * exif/iptc/xmp */ - include_once(LINPHA_DIR.'/lib/classes/linpha.exiftool.class.php'); - $MetaData = new LinExifTool(); + $MetaData = new LinMetaData(); /** * exif Modified: trunk/linpha2/templates/default/search.html.php =================================================================== --- trunk/linpha2/templates/default/search.html.php 2007-03-17 12:02:05 UTC (rev 4698) +++ trunk/linpha2/templates/default/search.html.php 2007-03-17 16:29:01 UTC (rev 4699) @@ -78,8 +78,7 @@ echo '<label for="b_'.$data['id'].'">'.$data['name'].'</label><br />'; } - include_once(LINPHA_DIR.'/lib/classes/linpha.exiftool.class.php'); - $MetaData = new LinExifTool(); + $MetaData = new LinMetaData(); /** * Exif/Iptc/Xmp Informations This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |