I have a php script that reads a very large multi-dimensional array (5000 items for example) that contains info plus URL's for images associated with the item. I set it up so that it makes a thumbnail of the image and saves the new image on a local directory after resizing. I think I have altered the Timeout settings so that a timeout will not occur. (edited the httpd.conf file on the TIMEOUT line)
It works fine but sometimes hits an image (say at the 2000th position) and then the script stops. This usually occurs during the call to the function that reads, resizes and makes the thumbnail. Here is the function:
/*--------------------------------------------------------------------------------
Function createthumb($name,$filename,$new_w,$new_h)
creates a resized image
variables:
$name Original filename
$filename Filename of the resized image
$new_w width of resized image
$new_h height of resized image
//--------------------------------------------------------------------------------*/
function createthumb($name,$filename,$new_w,$new_h){
global $gd2;
$gd2 = 1;
$system=explode(".",$name);
$rev_system = array_reverse($system);
if (preg_match("/jpg|jpeg/",$rev_system[0])){
$src_img=@imagecreatefromjpeg($name);
}
if (preg_match("/png/",$rev_system[0])){
$src_img=imagecreatefrompng($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
print("<br />$old_x is the X and $old_y is the Y!<br />");
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
if ($gd2==""){
$dst_img=ImageCreate($thumb_w,$thumb_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}else{
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}
if (preg_match("/png/",$system[1])){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
$imageProp['width'] = floor($thumb_w);
$imageProp['height'] = floor($thumb_h);
print("<br />Finished making image<br />");
return $imageProp;
}
When it stops, usually the last output line is something like "105 is the X and 166 is the Y!"
but the script does not continue even though there are more items in the array to loop through.
Any help on this would be great!
- John