Jump to content

Read image info from multiple files


prolethead

Recommended Posts

Hi,

I have two pieces of code, one that lists files in a directory, and one that reads image ipct header info from images. I want to be able to combine those pieces of code so I can print the header info for multiple image files.

Here's the readdir code:

[quote]if ($handle = opendir('.')) {
  while (false !== ($file = readdir($handle))) {
      echo "$file\n";
  }

  closedir($handle);
}[/quote]


Here's the icpt code:

[quote]$image_path = 'WHAT I WANT TO BE AN ARRAY';

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( $image_path );[/quote]

So I want to make output_iptc_data work for multiple files in a directory.

Thanks!
Link to comment
https://forums.phpfreaks.com/topic/31125-read-image-info-from-multiple-files/
Share on other sites

You need to just do put the call to the function inside the loop...

[code]<?php
if ($handle = opendir('.')) {
  while (($file = readdir($handle)) !== false){
      echo "$file\n";
      output_iptc_data($file);
  }
  closedir($handle);
}

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>\n";
        }
      }               
  }     
}
?>[/code]

Regards
Huggie

Archived

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

×
×
  • Create New...

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.