[Linpha-cvs] SF.net SVN: linpha: [4713] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <bz...@us...> - 2007-03-22 17:29:44
|
Revision: 4713 http://svn.sourceforge.net/linpha/?rev=4713&view=rev Author: bzrudi Date: 2007-03-22 10:28:37 -0700 (Thu, 22 Mar 2007) Log Message: ----------- improved MetaData write support (still buggy) Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/lib/classes/exiftool/xmp2iptc.args trunk/linpha2/lib/classes/linpha.exiftool.class.php trunk/linpha2/lib/classes/linpha.metadata.class.php trunk/linpha2/lib/include/metadata_iptc_edit.php trunk/linpha2/lib/include/metadata_xmp_edit.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2007-03-21 16:00:41 UTC (rev 4712) +++ trunk/linpha2/ChangeLog 2007-03-22 17:28:37 UTC (rev 4713) @@ -1,3 +1,6 @@ +2007-03-22 bzrudi + * Improved MetaData write support and started field type detection + 2007-03-21 bzrudi * Prepared support for extracting the embedded thumbnail from the EXIF segment of the images as thumbnail. Currently disabled by default. Modified: trunk/linpha2/lib/classes/exiftool/xmp2iptc.args =================================================================== --- trunk/linpha2/lib/classes/exiftool/xmp2iptc.args 2007-03-21 16:00:41 UTC (rev 4712) +++ trunk/linpha2/lib/classes/exiftool/xmp2iptc.args 2007-03-22 17:28:37 UTC (rev 4713) @@ -25,6 +25,7 @@ -XMP-photoshop:State > IPTC:Province-State -XMP-photoshop:Country > IPTC:Country-PrimaryLocationName -XMP-photoshop:TransmissionReference > IPTC:OriginalTransmissionReference +-XMP-photoshop:Urgency > IPTC:Urgency -XMP-dc:Rights > IPTC:CopyrightNotice -XMP-dc:Description > IPTC:Caption-Abstract -XMP-photoshop:CaptionWriter > IPTC:Writer-Editor Modified: trunk/linpha2/lib/classes/linpha.exiftool.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.exiftool.class.php 2007-03-21 16:00:41 UTC (rev 4712) +++ trunk/linpha2/lib/classes/linpha.exiftool.class.php 2007-03-22 17:28:37 UTC (rev 4713) @@ -116,8 +116,10 @@ $parameters = "-$metatype:all " . // Get all Tag Information "-s " . // Print tag names instead of descr. "-t " . // Use tab \t as delimiter - "-fast "; // Do not read to EOF - + "-fast " . // Do not read to EOF + "-n " . // Read numbers instead of words + "-m "; //Ignore minor errors + exec("$this->exiftool $parameters $filename", $meta, $return); //echo '<pre>', print_r($meta), '</pre>'; @@ -167,7 +169,8 @@ if(array_key_exists($key, $lowerDataArray)) { $str_columns .= str_replace("_", "-", $key) . ', '; - $str_values .= "'".HTML_UTF8_Escape(trim($lowerDataArray[$key]))."', "; + $str_values .= "'".trim($lowerDataArray[$key])."', "; + //$str_values .= "'".HTML_UTF8_Escape(trim($lowerDataArray[$key]))."', "; } } @@ -307,7 +310,7 @@ 'contributor' => 'Contributor', 'coverage' => 'Coverage', 'creator' => 'Creator', - 'date' => 'Date', + //'date' => 'Date', 'description' => 'Description', 'format' => 'Format', 'identifier' => 'Identifier', @@ -344,9 +347,10 @@ 'objecttypereference' => 'Object Type Reference', 'objectattributereference' => 'Object Attribute Reference', 'objectname' => 'Object Name', + 'objectcycle' => 'Object Cycle', 'editstatus' => 'Edit Status', 'subjectreference' => 'Subject Reference', - 'category' => 'Category', + //'category' => 'Category', 'supplementalcategories' => 'Supplemental Categories', 'keywords' => 'Keywords', 'specialinstructions' => 'Special Instructions', @@ -354,19 +358,21 @@ 'timecreated' => 'Time Created', 'by_line' => 'By-line', 'by_linetitle' => 'By-line Title', - 'city' => 'City', + //'city' => 'City', 'sub_location' => 'Sub-location', - 'provincestate' => 'Province-State', + 'province_state' => 'Province-State', 'country_primarylocationcode' => 'Country-Primary Location Code', 'country_primarylocationname' => 'Country-Primary Location Name', 'originaltransmissionreference' => 'Original Transmission Reference', - 'headline' => 'Headline', - 'credit' => 'Credit', - 'source' => 'Source', + //'headline' => 'Headline', + //'credit' => 'Credit', + //'source' => 'Source', 'copyrightnotice' => 'Copyright Notice', 'contact' => 'Contact', 'caption_abstract' => 'Caption-Abstract', - 'writer_editor' => 'Writer-Editor' + 'writer_editor' => 'Writer-Editor', + 'originatingprogram' => 'Originating Program', + 'releasedate' => 'Release Date' ), //EXIF schema tags Modified: trunk/linpha2/lib/classes/linpha.metadata.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.metadata.class.php 2007-03-21 16:00:41 UTC (rev 4712) +++ trunk/linpha2/lib/classes/linpha.metadata.class.php 2007-03-22 17:28:37 UTC (rev 4713) @@ -443,12 +443,16 @@ } $meta_array['linDoBackup'] = false; } - if(!isset($meta_array['linMassUpdate'])) + + if(!isset($meta_array['linRecursiveUpdate'])) { - $meta_array['linMassUpdate'] = false; - } + $recursive_update = false; + } + else + { + $recursive_update = true; + } - /** * See if we should create file backup first. If it went wrong, * exit with $write_ok = false @@ -483,107 +487,109 @@ * Prevent exiftool from backing up file, as we do take * care of it our own :-) */ - $parameter = "-overwrite_original "; + $parameter = "-overwrite_original -n "; /** * Update all images in folder with given MetaData, * therefore we need to fake file to dirname instead */ - if($meta_array['linMassUpdate']) + if($recursive_update) { $file = dirname($GLOBALS['linpha']->imgview->src_file); $parameter .= "-r " . // Recursive - "-ext jpeg -ext jpg -ext tif -ext tiff "; + "-ext jpeg " . // Filetype + "-ext jpg " . + "-ext tif " . + "-ext tiff "; } /** - * Apply IPTC MetaData also to XMP and vice versa + * Apply XMP MetaData to IPTC Segment */ - if(!isset($meta_array['linViceVersa'])) + if(!isset($meta_array['linXmp2Iptc'])) { - $vice_versa = false; + $xmp2iptc = false; } else { - $vice_versa = true; + $xmp2iptc = true; } unset ($meta_array['linDoBackup']); - unset ($meta_array['linMassUpdate']); - unset ($meta_array['linViceVersa']); + unset ($meta_array['linRecursiveUpdate']); + unset ($meta_array['linXmp2Iptc']); /** * Go ahead write MetaData */ - if($vice_versa) + if($_POST['linCmd'] == 'linInsertMetaIptc') { - $metaTag = array('iptc', 'xmp'); - } - elseif($_POST['linCmd'] == 'linInsertMetaIptc') - { $metaTag = 'iptc'; } elseif($_POST['linCmd'] == 'linInsertMetaXmp') { $metaTag = 'xmp'; } + + foreach($meta_array AS $name => $value) + { + if(strlen(trim($value)) >= 1) + { + $name = str_replace("_", "-", $name); + $parameter .= "-$metaTag:$name='$value' "; + } + } + } + //echo '<pre>', print_r($meta_array), '</pre>'; + //echo "PARA :".$parameter; + + /** + * Finally fire up exiftool + * TODO: take care of response status + */ + exec("$exiftool $parameter $file"); - - if(is_array($metaTag)) // ViceVersa Request - { - foreach($metaTag AS $segment) - { - foreach($meta_array AS $name => $value) - { - if(strlen(trim($value)) >= 1) - { - $name = str_replace("_", "-", $name); - $parameter .= "-$segment:$name='$value' "; - } - } - } - } - else - { - foreach($meta_array AS $name => $value) - { - if(strlen(trim($value)) >= 1) - { - $name = str_replace("_", "-", $name); - $parameter .= "-$metaTag:$name='$value' "; - } - } - } - //echo '<pre>', print_r($meta_array), '</pre>'; - //echo "parm".$parameter; - - /** - * Finally fire up exiftool - * TODO: take care of response status - */ - exec("$exiftool $parameter $file"); - - /** - * force read data from file again if write was successful - */ - unset ($meta_array); - LinImport:: - updateEntry($GLOBALS['linpha']->template->idCurrent, + /** + * Copy XMP to IPTC if needed + * $parameter tags copied from xmp2iptc.args file from the + * exiftool distribution + */ + if($xmp2iptc) + { + echo "MAKE COPY"; + $options = " -TagsFromFile "; + + if($recursive_update) + { + $options .= "-r " . + "-ext jpeg -ext jpg -ext tif -ext tiff "; + } + + $arguments = LINPHA_DIR.'/lib/classes/exiftool/xmp2iptc.args'; + + exec("$exiftool $options $file -@ $arguments $file"); + } + + /** + * force read data from file again if write was successful + */ + unset ($meta_array); + LinImport:: + updateEntry($GLOBALS['linpha']->template->idCurrent, dirname($GLOBALS['linpha']->imgview->src_file), basename($GLOBALS['linpha']->imgview->src_file)); - } - else - { - linSysLog(sprintf(i18n("Error: Processing of: %s failed, " . - "please check write permissions"), - $GLOBALS['linpha']->imgview->src_file)); - linLog(LOG_TYPE_META, LOG_ERR, 'meta_data', "Error: " . - "Processing failed for: ".' ' . - $GLOBALS['linpha']->imgview->src_file); - } + } + else + { + linSysLog(sprintf(i18n("Error: Processing of: %s failed, " . + "please check write permissions"), + $GLOBALS['linpha']->imgview->src_file)); + linLog(LOG_TYPE_META, LOG_ERR, 'meta_data', "Error: " . + "Processing failed for: ".' ' . + $GLOBALS['linpha']->imgview->src_file); } - } + } } Modified: trunk/linpha2/lib/include/metadata_iptc_edit.php =================================================================== --- trunk/linpha2/lib/include/metadata_iptc_edit.php 2007-03-21 16:00:41 UTC (rev 4712) +++ trunk/linpha2/lib/include/metadata_iptc_edit.php 2007-03-22 17:28:37 UTC (rev 4713) @@ -24,6 +24,7 @@ */ if(!defined('LINPHA_DIR')) { exit(1); } + ?> <tr><td rwospan="2"> <input type='checkbox' name='linDoBackup' checked> @@ -31,64 +32,152 @@ </td> </tr> <tr><td rwospan="2"> - <input type='checkbox' name='linViceVersa' checked> - <?php echo i18n("Apply MetaData Also To XMP Segment"); ?> + <input type='checkbox' name='linRecursiveUpdate'> + <?php echo i18n("Apply To All Images In Album"); ?> </td> </tr> +<?php +/* <tr><td rwospan="2"> - <input type='checkbox' name='linMassUpdate'> - <?php echo i18n("Apply To All Images In Album"); ?> + <input type='checkbox' name='linViceVersa' checked> + <?php echo i18n("Apply MetaData Also To XMP Segment"); ?> </td> </tr> -<?php - +*/ +/** + * We are going to save all IPTC data UTF8 encoded in database + */ include_once(LINPHA_DIR.'/lib/classes/pjmt/Unicode.php'); + $MetaData = new LinMetaData(); $MetaData->setMetaFields('iptc'); $file_data = $MetaData->objMetaTool->readMetaDataFromFile('iptc', $filename); +/** + * User may have selected all fields, so there are no available fields left + * create emtpy array to prevent notices... + */ $iptc_avail = $MetaData->available_fields['iptc']; if(!is_array($iptc_avail)){ $iptc_avail = array(); }; - +/** + * User may have selected not even a single field for now, so there are no + * selected fields, create emtpy array to prevent notices... + */ $iptc_defined = $MetaData->defined_fields['iptc']; if(!is_array($iptc_defined)){ $iptc_defined = array(); }; /** - * Merge arrays + * Merge both arrays to make all fields avail */ $iptc_array = $iptc_avail + $iptc_defined; -//var_dump($file_data); - /** * Now output the actual HTML form */ - foreach($iptc_array AS $name => $value) { $lower_array = array_change_key_case($file_data, CASE_LOWER); - $name = str_replace("_", "-", $name); - + if(isset($lower_array[$name])) { - $file_iptc = HTML_UTF8_Escape($lower_array[$name]); + $file_iptc = HTML_UTF8_Escape(trim($lower_array[$name])); } else { $file_iptc = ""; } - echo - "<tr>" . - "<td>$value</td>" . - "<td> ". - "<input size=55 class='linForms' name='$name' - type='text' value='".$file_iptc."'>" . - "</td>" . - "</tr>"; + /** + * We need to take care of some special fields, e.g. special length, + * special types (select field) and so on... + */ + //echo $name."<br>"; + //echo $file_iptc."<br>"; + switch($name) + { + case 'objectcycle': + $sel_a = ""; + $sel_b = ""; + $sel_c = ""; + + switch($file_iptc) + { + case 'a': + $sel_a = "selected"; + break; + case 'b': + $sel_b = "selected"; + break; + case 'c': + $sel_c = "selected"; + break; + } + echo + "<tr>" . + "<td>$value</td>" . + "<td> ". + "<select name='$name' style='width:350px; size='1' + class='linForms'>" . + "<option value='a' $sel_a>Morning</option>" . + "<option value='b' $sel_b>Afternoon</option>" . + "<option value='c' $sel_c>Evening</option>" . + "</td>" . + "</tr>"; + break; -} + case 'caption-abstract': + echo + "<tr>" . + "<td>$value</td>" . + "<td> ". + "<textarea style='width:350px; height:60px;' class='linForms' + name='$name'>$file_iptc</textarea>" . + "</td>" . + "</tr>"; + break; + + case 'urgency': + /** + * Fast easy init ;-) + */ + for($i = 0; $i <= 8; $i++) + { + $sel[$i] = " "; + } + $sel[$file_iptc] = "selected"; + + echo + "<tr>" . + "<td>$value</td>" . + "<td> ". + "<select name='$name' style='width:350px; size='1' + class='linForms'>" . + "<option value='0' $sel[0]>0: None</option>" . + "<option value='1' $sel[1]>1: High</option>" . + "<option value='2' $sel[2]>2: </option>" . + "<option value='3' $sel[3]>3: </option>" . + "<option value='4' $sel[4]>4: </option>" . + "<option value='5' $sel[5]>5: Normal</option>" . + "<option value='6' $sel[6]>6: </option>" . + "<option value='7' $sel[7]>7: </option>" . + "<option value='8' $sel[8]>8: Low</option>" . + "</td>" . + "</tr>"; + break; + + default: + echo + "<tr>" . + "<td>$value</td>" . + "<td> ". + "<input style='width:350' class='linForms' name='$name' + type='text' value='".$file_iptc."'>" . + "</td>" . + "</tr>"; + } +} +/* vi: set ts=4 sw=4 sts=4 */ ?> Modified: trunk/linpha2/lib/include/metadata_xmp_edit.php =================================================================== --- trunk/linpha2/lib/include/metadata_xmp_edit.php 2007-03-21 16:00:41 UTC (rev 4712) +++ trunk/linpha2/lib/include/metadata_xmp_edit.php 2007-03-22 17:28:37 UTC (rev 4713) @@ -31,12 +31,12 @@ </td> </tr> <tr><td rwospan="2"> - <input type='checkbox' name='linViceVersa' checked> + <input type='checkbox' name='linXmp2Iptc' checked> <?php echo i18n("Apply MetaData Also To IPTC Segment"); ?> </td> </tr> <tr><td rwospan="2"> - <input type='checkbox' name='linMassUpdate'> + <input type='checkbox' name='linRecursiveUpdate'> <?php echo i18n("Apply To All Images In Album"); ?> </td> </tr> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |