Page 1 of 1

Thumbnail resize code, worked great until.....

Posted: Mon Mar 02, 2009 6:38 pm
by randomtaiwanese
I have a thumbnail creation code:

Code: Select all

 
function makeThumbs($file){
    $target_path = "images/".$file; 
        
    $src = imagecreatefromjpeg($target_path);
    
    list($width,$height) = getimagesize($target_path);
    
    if($width>$height){
        $new_width = 150;
        $new_height = ($height/$width)*$new_width;
    }else{
        $new_height = 150;
        $new_width = ($width/$height)*$new_height;
    }
    $tmp = imagecreatetruecolor($new_width,$new_height);
    
    imagecopyresampled($tmp,$src,0,0,0,0,$new_width,$new_height,$width,$height);
    
    $target_path = "images/thumbs/".$file;
 
    imagejpeg($tmp,$target_path,100);
    
    imagedestroy($src);
    imagedestroy($tmp);
}
 
It worked great until I tried it on a bunch of random images just to make sure it all works out.
Then these two images are giving headaches because for whatever reason, they just fail the script:

http://nuphoto.org/temp/1%20free%20internet.jpg
I think this is more of a filename issue, but i tired adding
$file = str_replace(" ","%20",$file)
into the code, and it stopped creating thumbnails....

and this:
http://nuphoto.org/temp/605120605341539.jpg
this one is really troublesome. i tried to debug it and found that it kills the script after this line:
$src = imagecreatefromjpeg($target_path);
help?

Re: Thumbnail resize code, worked great until.....

Posted: Mon Mar 02, 2009 8:02 pm
by omniuni
I think it's just that they're big files. Try increasing the script's memory limit to 64 megabytes, and see if that fixes it.

Re: Thumbnail resize code, worked great until.....

Posted: Mon Mar 02, 2009 8:08 pm
by randomtaiwanese
omniuni wrote:I think it's just that they're big files. Try increasing the script's memory limit to 64 megabytes, and see if that fixes it.
how can this be achieved?

what about the first file? the function seems to not like the space in the file name also.

Re: Thumbnail resize code, worked great until.....

Posted: Tue Mar 03, 2009 10:03 am
by pickle
Rather than replacing %20 specifically, use urldecode(). imagecreatefromjpeg() shouldn't care if there's a space in the name - I doubt that's what's causing the problem.

How big (in KB) are these images?

Look into ini_set() to change the memory allotment.