[Linpha-cvs] SF.net SVN: linpha: [4711] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <bz...@us...> - 2007-03-21 15:49:38
|
Revision: 4711 http://svn.sourceforge.net/linpha/?rev=4711&view=rev Author: bzrudi Date: 2007-03-21 08:43:38 -0700 (Wed, 21 Mar 2007) Log Message: ----------- XMP/IPTC write support plus some more additions and improvements Modified Paths: -------------- trunk/linpha2/ChangeLog 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 trunk/linpha2/templates/default/fragments.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2007-03-21 12:41:45 UTC (rev 4710) +++ trunk/linpha2/ChangeLog 2007-03-21 15:43:38 UTC (rev 4711) @@ -1,7 +1,12 @@ 2007-03-21 bzrudi * Prepared support for extracting the embedded thumbnail from the EXIF segment of the images as thumbnail. Currently disabled by default. + * Added basic XMP write support * Added basic IPTC write support + + Option to save both, IPTC fields in XMP and vice versa in one step + + Option to save MetaData to all files in album at once, which is + pretty handy I think :-) + + Option to toggle file backup before writing MetaData TODO: Create all MetaData table columns with their right datatype defined CHAR/TEXT/INT/VARCHAR and so on. IPTC and XMP expect some data values with a defined length and Modified: trunk/linpha2/lib/classes/linpha.exiftool.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.exiftool.class.php 2007-03-21 12:41:45 UTC (rev 4710) +++ trunk/linpha2/lib/classes/linpha.exiftool.class.php 2007-03-21 15:43:38 UTC (rev 4711) @@ -115,7 +115,8 @@ $parameters = "-$metatype:all " . // Get all Tag Information "-s " . // Print tag names instead of descr. - "-t "; // Use tab \t as delimiter + "-t " . // Use tab \t as delimiter + "-fast "; // Do not read to EOF exec("$this->exiftool $parameters $filename", $meta, $return); //echo '<pre>', print_r($meta), '</pre>'; Modified: trunk/linpha2/lib/classes/linpha.metadata.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.metadata.class.php 2007-03-21 12:41:45 UTC (rev 4710) +++ trunk/linpha2/lib/classes/linpha.metadata.class.php 2007-03-21 15:43:38 UTC (rev 4711) @@ -383,8 +383,8 @@ /** * This method takes care of storing modified MetaData. It takes care - * whether we are trying to save "own" LinPHA MetaData or MetaData found - * in images (EXIF,IPTC,XMP) + * whether we are trying to save "own" LinPHA MetaData or MetaData + * to be stored in the image itself images (EXIF,IPTC,XMP) * @param none * @return none * @author flo, bzrudi @@ -404,61 +404,182 @@ } /** - * Write iptc data - * TODO rewrite! + * Write IPTC/XMP MetaData to file */ if(isset($_POST['linCmd']) - && $_POST['linCmd'] == 'linInsertMetaIptc' - && $GLOBALS['linpha']->sql->config->value['sys_image_iptc'] && isset ($GLOBALS['linpha']->imgview->src_file) && file_exists($GLOBALS['linpha']->imgview->src_file)) { - global $iptc_array; - $iptc_array = $GLOBALS['_POST']; - + global $meta_array; + $meta_array = $GLOBALS['_POST']; + /** * Important! * Remove other POST data from this array, because we just * take all values and this will generate unexpected results!!! * We got problems because $_POST['linMetaField'] is an array. */ - unset ($iptc_array['linCmd']); - unset ($iptc_array['linMetaField']); - unset ($iptc_array['submit']); + unset ($meta_array['linCmd']); + unset ($meta_array['linMetaField']); + unset ($meta_array['submit']); /** - * if the backup went wrong, the saveModifiedMetaDataIptc() would most probably also fail + * Prevent notices from unset checkboxes and make sure to + * set to false if unset */ - if(LinFilesys::backupFile($GLOBALS['linpha']->imgview->src_file)) + if(!isset($meta_array['linDoBackup'])) + { + /** + * If user wants no backup, make at least sure file is + * writeable, or break later + */ + if(is_writable($GLOBALS['linpha']->imgview->src_file)) + { + $write_ok = true; + } + else + { + $write_ok = false; + } + $meta_array['linDoBackup'] = false; + } + if(!isset($meta_array['linMassUpdate'])) + { + $meta_array['linMassUpdate'] = false; + } + + + /** + * See if we should create file backup first. If it went wrong, + * exit with $write_ok = false + */ + if($meta_array['linDoBackup']) { - $parameter = "-overwrite_original "; + if(LinFilesys + ::backupFile($GLOBALS['linpha']->imgview->src_file)) + { + $write_ok = true; + } + else + { + $write_ok = false; + } + } - foreach($iptc_array AS $name => $value) - { - if(strlen(trim($value)) >= 1) - { - $name = str_replace("_", "-", $name); - $parameter .= "-iptc:$name='$value' "; - } - } - //echo '<pre>', print_r($iptc_array), '</pre>'; - + /** + * If the backup went wrong or file isn't writable, trying + * to write MetaData would most probably also fail, so skip it + */ + if($write_ok) + { + /** + * Fire up exiftool + */ LinMetaData::__construct(); $file = $GLOBALS['linpha']->imgview->src_file; $exiftool = $this->objMetaTool->exiftool; + /** + * Prevent exiftool from backing up file, as we do take + * care of it our own :-) + */ + $parameter = "-overwrite_original "; + + /** + * Update all images in folder with given MetaData, + * therefore we need to fake file to dirname instead + */ + if($meta_array['linMassUpdate']) + { + $file = dirname($GLOBALS['linpha']->imgview->src_file); + $parameter .= "-r "; // Recursive + } + + /** + * Apply IPTC MetaData also to XMP and vice versa + */ + if(!isset($meta_array['linViceVersa'])) + { + $vice_versa = false; + } + else + { + $vice_versa = true; + } + + unset ($meta_array['linDoBackup']); + unset ($meta_array['linMassUpdate']); + unset ($meta_array['linViceVersa']); + + + /** + * Go ahead write MetaData + */ + if($vice_versa) + { + $metaTag = array('iptc', 'xmp'); + } + elseif($_POST['linCmd'] == 'linInsertMetaIptc') + { + $metaTag = 'iptc'; + } + elseif($_POST['linCmd'] == 'linInsertMetaXmp') + { + $metaTag = 'xmp'; + } + + + if(is_array($metaTag)) // ViceVersa Request + { echo "VICE VERSA"; + 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 ($iptc_array); - LinImport :: updateEntry($GLOBALS['linpha']->template->idCurrent, dirname($GLOBALS['linpha']->imgview->src_file), basename($GLOBALS['linpha']->imgview->src_file)); + 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: Cannot create backup of: %s"), $GLOBALS['linpha']->imgview->src_file)); - linLog(LOG_TYPE_META, LOG_ERR, 'meta_iptc', "Error: Cannot create backup of:" . ' ' . $GLOBALS['linpha']->imgview->src_file); + 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 12:41:45 UTC (rev 4710) +++ trunk/linpha2/lib/include/metadata_iptc_edit.php 2007-03-21 15:43:38 UTC (rev 4711) @@ -24,6 +24,23 @@ */ if(!defined('LINPHA_DIR')) { exit(1); } +?> +<tr><td rwospan="2"> + <input type='checkbox' name='linDoBackup' checked> + <?php echo i18n("Backup Original File"); ?> + </td> +</tr> +<tr><td rwospan="2"> + <input type='checkbox' name='linViceVersa' checked> + <?php echo i18n("Apply MetaData Also To XMP Segment"); ?> + </td> +</tr> +<tr><td rwospan="2"> + <input type='checkbox' name='linMassUpdate'> + <?php echo i18n("Apply To All Images In Album"); ?> + </td> +</tr> +<?php include_once(LINPHA_DIR.'/lib/classes/pjmt/Unicode.php'); Modified: trunk/linpha2/lib/include/metadata_xmp_edit.php =================================================================== --- trunk/linpha2/lib/include/metadata_xmp_edit.php 2007-03-21 12:41:45 UTC (rev 4710) +++ trunk/linpha2/lib/include/metadata_xmp_edit.php 2007-03-21 15:43:38 UTC (rev 4711) @@ -24,6 +24,23 @@ */ if(!defined('LINPHA_DIR')) { exit(1); } +?> +<tr><td rwospan="2"> + <input type='checkbox' name='linDoBackup' checked> + <?php echo i18n("Backup Original File"); ?> + </td> +</tr> +<tr><td rwospan="2"> + <input type='checkbox' name='linViceVersa' checked> + <?php echo i18n("Apply MetaData Also To IPTC Segment"); ?> + </td> +</tr> +<tr><td rwospan="2"> + <input type='checkbox' name='linMassUpdate'> + <?php echo i18n("Apply To All Images In Album"); ?> + </td> +</tr> +<?php $MetaData = new LinMetaData(); $MetaData->setMetaFields('xmp'); Modified: trunk/linpha2/templates/default/fragments.php =================================================================== --- trunk/linpha2/templates/default/fragments.php 2007-03-21 12:41:45 UTC (rev 4710) +++ trunk/linpha2/templates/default/fragments.php 2007-03-21 15:43:38 UTC (rev 4711) @@ -204,12 +204,12 @@ <img style="margin-left: 20px;" src="<?php echo LINPHA_CLIENT.'/get_thumb.php?linId='.$GLOBALS['linpha']->template->idCurrent; ?>" width="<?php echo $GLOBALS['linpha']->sql->config->value['sys_style_thumb_size_display']; ?>" height="<?php echo $GLOBALS['linpha']->sql->config->value['sys_style_thumb_size_display']; - ?>" /> - + ?>" /> + <?php if($GLOBALS['linpha']->imgview->img_type!=0) { ?> <div id="linDivMetaIptc"> <?php if($GLOBALS['linpha']->sql->config->value['sys_image_iptc']) { - echo '<br /><br />'; + echo '<br />'; if($meta_edit_possible) { ?> <form action="<?php echo $linTpl->URL_full; ?>" method="POST"> <table border="0"> @@ -245,6 +245,7 @@ <?php if($GLOBALS['linpha']->imgview->img_type!=0) { ?> <div id="linDivMetaXmp"> <?php if($GLOBALS['linpha']->sql->config->value['sys_image_xmp']) { + echo '<br />'; if($meta_edit_possible) { ?> <form action="<?php echo $linTpl->URL_full; ?>" method="POST"> <table border="0"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |