Put the enclosed PHP code below into the dirctory "www"- the original pictures into "album" a subdirectory of "MesPhotos",
then, a typical link for the display will be :

<a href="MesPhotos/album/p210.jpg"><img src="MesPhotos/album/albump/p210.jpg" title="Rio-Copacabana"></a>

with :

MesPhotos/album/p210.jpg = path to the original picture
MesPhotos/album/albump/p210.jpg = path to the miniatured picture
title="your comment" which will appear when the mouse goes over the miniature.

Meaning of the Variables and Comments ------------------------

$Dossier = absolute path to the original pictures, whose names will be converted to lowercase if needed.
$mindossier = sub-directory where the miniatures will be stored with the same name of their original picture.
$largeurDestination = width in pixels of the miniature.
$hauteurDestination = height in pixels of the miniature.
(for a vertical picture, the pixels of the width and the pixels of the height will be permuted)

Warning : if there are many pictures to convert, man could get a "Time Out" failure (operating time over 30 secondes).
I didn't find to eliminate that problem !!
	
The PHP Code:		
<?php 
$Dossier ="d:/EasyPHP1-7/www/MesPhotos/album/";
$mindossier = $Dossier."albump/";
$dir = opendir ($Dossier);
chmod($Dossier,0777);
chmod($mindossier,0777);
while ($file = readdir($dir)) {
	$Image = strtolower($file);
	echo "$Image"."<br>";
	if($Image !== $file) {
	   rename($Dossier.$file,$Dossier.$Image) 
	   or die("unable to rename $file to $Image:$php_errormsg");
	}   	
	if(substr($Image,-4) == '.jpg') {
	   $fichierSource = $Dossier.$file;
	   $size = getimagesize($fichierSource); 
        if($size[0] > $size[1]){  
           $largeurDestination = 160;
           $hauteurDestination = 120;
	       } 
	       else {
	      $largeurDestination = 120;
          $hauteurDestination = 160;
	  }
     $im = @ImageCreateTrueColor ($largeurDestination, $hauteurDestination) 
            or die ("Error when creating the picture"); 
     $source = ImageCreateFromJpeg($fichierSource);
     $largeurSource = imagesx($source);
     $hauteurSource = imagesy($source);
	 ImageCopyResampled($im, $source, 0, 0, 0, 0, $largeurDestination, $hauteurDestination, $largeurSource, $hauteurSource);
     $miniature = $mindossier.$Image;
     ImageJpeg ($im, $miniature); 
     echo "miniatured picture generated : $miniature"."<br>";
	}
}
closedir ($dir);	
?>
top
© JPSoft - 2004