Hello,
I am a novice PHP scripter. I mostly create small things or adjust php scripts i find online slightly and use them. This time I am having a problem.
This script takes images in a directory, makes thumbnails of the images 1 by 1 in it and puts it in "thumbs" directory.
It works fine, but if I have a lot of images, once it gets to about 30 seconds in... it just stops, with no errors, the browser says "Done" (firefox).
set_time_limit(0);
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
$dir = opendir( $pathToImages );
while (false !== ($fname = readdir( $dir ))) {
$info = pathinfo($pathToImages . $fname);
if ( strtolower($info['extension']) == 'jpg' )
{
echo "Creating thumbnail for {$fname} <br>";
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
}
}
echo "done1";
closedir( $dir );
echo "done2";
}
I tried for fun the two "echo"s at the end, it never reaches that.
I also tried "set_time_limit(0);" at the top, I dont know if I used that correctly, but ya..
Anyone have any ideas?
Thanks,
Kenny