I'm using a script for resize photos to another folder and keep the same name automaticaly found here and working great!
I have hundreds of photos in my source folder and i'm going to do this action often. I would like to optimize the time by making it resize the photos only if it sees the photos doesn't exist in the destination folder. How can we do that?
Here is the full code used:
function imageResize($file, $path, $height, $width)
{
$target = 'smallphotos/';
$handle = opendir($path);
if($file != "." && $file != ".." && !is_dir($path.$file))
{
$thumb = $path.$file;
$imageDetails = getimagesize($thumb);
$originalWidth = $imageDetails[0];
$originalHeight = $imageDetails[1];
if($originalWidth > $originalHeight)
{
$thumbHeight = $height;
$thumbWidth = ($originalWidth/($originalHeight/$thumbHeight));
}
else
{
$thumbWidth = $width;
$thumbHeight = ($originalHeight/($originalWidth/$thumbWidth));
}
$originalImage = ImageCreateFromJPEG($thumb);
$thumbImage = ImageCreateTrueColor($thumbWidth, $thumbHeight);
ImageCopyResized($thumbImage, $originalImage, 0, 0, 0, 0, $thumbWidth,
$thumbHeight, $originalWidth, $originalHeight);
$filename = $file;
imagejpeg($thumbImage, $target.$filename, 100);
}
closedir($handle);
}
$source = "photos";
$directory = opendir($source);
//Scan through the folder one file at a time
while(($file = readdir($directory)) != false)
{
echo "<br>".$file;
//Run each file through the image resize function
imageResize($file, $source.'/', 640, 480);
}