Hi, I'm using a simple image resize script from phptoys.com to create a batch of thumbnails... I keep getting the error:
Fatal error: Maximum execution time of 30 seconds exceeded in /blahblahblah/resizeimage.php on line 43
Here's the code I'm calling in that gives the error:
function resizeImage($originalImage,$toWidth,$toHeight){
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;
// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}
// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}
here's my code that calls it in:
echo 'looping through photos<br / >';
while (($file = $images->read()) !== false)
{
//name image file
$imgpath=$albumf.'/slides/'.$file;
//name thumbnail file
$thumbpath=$albumf.'/thumbs/'.$file;
//avoid .htaccess, subfolders etc
if (($file[0] !== '.') && (is_file($imgpath))) {
list($width, $height) = getimagesize($imgpath);
//calculate thumb size
$thumbw= round($width/$height*$thumbh);
echo 'creating thumbnail for '.$file.'';
//Resize the image
$newthumb = resizeImage($imgpath,$thumbw,$thumbh);
// Create the thumbnail file
imagejpeg($newthumb,$thumbpath,100);
// leave permissions open on thumbnail
chmod ($thumbpath, 0777);
echo ' and the xml code<br / >';
//a whole load of other stuff irrelevant to this problem!
}}
this is part of a loop that goes through a folder of jpegs, creating thumbnails in a separate folder and doing some other stuff. Any ideas what's causing this timeout? It only happens on the live server - my server at home handles it without a blip.
It's always dying on a different image, so it's not that there's a dodgy image in there.