Jump to content


Photo

php iptc extraction, jpgs, and save for web curiosities


  • Please log in to reply
No replies to this topic

#1 bullchina

bullchina
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationHouston

Posted 05 September 2006 - 05:11 PM

I realize photoshop save for web strips iptc data, but i read somewhere that imageready's "save optimized as..." does keep the iptc data, etc...

i have this script that runs through a directory, and stores the title , description, and copyright info from iptc tags in each jpg in the folder, and it works for images saved with save as... in photoshop, but not for images saved in imageready's save optimized as...

<?php 
if (isset($dir)){
	$images = array();
	$imagecount = 0;
	// Open a known directory, and proceed to read its contents
	if (is_dir($dir)) {
		if ($dh = opendir($dir)) {
			while (($file = readdir($dh)) !== false) {			
				if (substr(	$file, count($file)-5,4) == ".jpg"){				
					//set paths to image and thumbnail
					$images[$imagecount]["path"] = $dir.$file;
					$images[$imagecount]["thumb"] = $dir."thumbnails/".$file;	
					//grab iptc data							
					$size = getimagesize ( $dir . $file, $info);       
					if(is_array($info)) {
						$iptc = iptcparse($info["APP13"]);
						foreach (array_keys($iptc) as $s) {             
							$c = count ($iptc[$s]);
							for ($i=0; $i <$c; $i++){
								if ($s == "2#120")
									$images[$imagecount]["description"] = $iptc[$s][$i];
								if ($s == "2#005")
									$images[$imagecount]["title"] = $iptc[$s][$i];
								if ($s == "2#116")
									$images[$imagecount]["copyright"] = $iptc[$s][$i];
							}
						}                 
					}			
					$imagecount++;			
				}        	
			}//end while loop for directory
		closedir($dh);
		}
	}
}
?>

it really drove me crazy, until i just decided to use save as in photoshop, and forget about imageready, unless someone knows how to fix it, or what is actually wrong.

the error i got said something to the effect of:

must supply an array type for the first argument of array_keys() function. 
to me that means imageready stores the metadata in a different way than photoshop, but anyways, i tried this code:

<?php
function output_iptc_data( $image_path ) {   
   $size = getimagesize ( $image_path, $info);       
     if(is_array($info)) {   
       $iptc = iptcparse($info["APP13"]);
       foreach (array_keys($iptc) as $s) {             
           $c = count ($iptc[$s]);
           for ($i=0; $i <$c; $i++)
           {
               echo $s.' = '.$iptc[$s][$i].'<br>';
           }
       }                 
   }           
}

output_iptc_data("bcnactiva/1.jpg");
?>

with the imageready images, and it worked... weird... thanks for any help that can be provided...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users