Jump to content

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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