I have script that rename and resize ca. 500 images in one folder.
After the 30 seconds execution I got this error:
Fatal error: Maximum execution time of 30 seconds exceeded in c:\inetpub\wwwroot\sparts\admin\optiimage.php on line 12
My Script:
function thumbs($file_name_src, $file_name_dest, $weight, $quality=100)
{
$size = getimagesize($file_name_src);
$w = number_format($weight, 0, ',', '');
$h = number_format(($size[1]/$size[0])*$weight,0,',','');
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
$src = imagecreatefromjpeg($file_name_src);
imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
imagejpeg($dest,$file_name_dest, $quality);
}
$path = "../images/spareparts/";
if ($handle = opendir($path)) {
$count = 0;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (preg_match("/JPG$/" ,$file)) {
$oldname = $path.$file;
$newname = strtolower($oldname);
rename($oldname, $newname);
$count++;
$image = $newname;
} else {
$image = $path.$file;
}
$imgSize = getimagesize($image);
if ($imgSize[0] > 200) {
thumbs($image, $image, 200, $quality=100);
}
}
}
closedir($handle);
}
I understand the problem because after 30 seconds are only 111 files processed.
What can I do to resolve the problem? Execute an external file 500 times?