Jump to content

Archived

This topic is now archived and is closed to further replies.

bullchina

php iptc extraction, jpgs, and save for web curiosities

Recommended Posts

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...

[code]<?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);
}
}
}
?>[/code]

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:

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

[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");
?>[/code]

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.