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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
randomtaiwanese
Forum Newbie
Posts: 2
Joined: Mon Mar 02, 2009 6:27 pm

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

Post 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?
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

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

Post 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.
randomtaiwanese
Forum Newbie
Posts: 2
Joined: Mon Mar 02, 2009 6:27 pm

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

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply