[thelist] listing width and height of all pix in a directory

joe stowaway at uklinux.net
Mon Dec 15 03:30:32 CST 2003


Joel D Canfield wrote:

>Is there a reasonably simple way to automatically output the width and
>height of all the jpg or gif files in a directory to a text file? 
>
>joel
>  
>
  
Hi Joel

I have a php script which does something simlar - the following code is 
adapted from it - you need to put the path to your image directory in 
the first line - the text file is saved in the image directory as 
'imageFile.txt'

hth

joe

<?php
       
    // edit this line to your path
    $pathToImageDir = "path/to/your/image/directory";
   
    $listOfFiles = getDirFileContents($pathToImageDir);
   
    $textFile = tempnam ("/tmp", "ImageList.txt");
    $handle = fopen($textFile, "w");
    fwrite($handle, $listOfFiles);
    fclose($handle);

    copy ($textFile, $pathToImageDir.'/imageFile.txt');

    function getDirFileContents($whichdir)
        {

        // files to ignore - add any others you know of
        $exclusions[] = ".";
        $exclusions[] = "..";

        $handle = @opendir($whichdir);
        while($file = @readdir($handle))
            {
            if ((!(is_dir($whichdir."/".$file))) && (!(in_array($file, 
$exclusions))))
                {
                $output .= getImageDimensions($whichdir."/".$file);
                }
            }
        closedir($handle);
        return $output;
        }

    function getImageDimensions($myImage)
        {
            $imagesize = getImageSize($myImage);
            $width = $imagesize[0];
            $height = $imagesize[1];
            $stringToReturn = $myImage . ": " . $width . " x " . $height 
. "\n";
            return $stringToReturn;
            }
    ?>


More information about the thelist mailing list