Thumbnail function now creates "grey" thumbnails?

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
webcan
Forum Commoner
Posts: 66
Joined: Tue Oct 28, 2003 2:25 pm
Location: Toronto, Canada

Thumbnail function now creates "grey" thumbnails?

Post by webcan »

Hey guys -

I have this function:

Code: Select all

function createThumbnail($image_path, $image_id, $file, $width, $height, $compression) { 
        copy($file, "$image_path/$image_id");
	    $src_img = imagecreatefromJPEG("$image_path/$image_id"); 
	    $new_h = $height;
	    $new_w = $width;
	    $dst_img = imagecreate($new_w,$new_h); 
	    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img)); 
	    imagejpeg($dst_img, "$image_path/$image_id", $compression); 
	}
It used to work fine, all the thumbnails were created reasonably well. But recently we updated the version of PHP and now the thumbnails come out very grey looking. It appears if some of the colors are just "missing" (although it's not quite black&white).

Any suggestions what I can do to fix it?

Thanks,
Peter.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Try replacing imagecreate() with imagecreatetruecolor().
webcan
Forum Commoner
Posts: 66
Joined: Tue Oct 28, 2003 2:25 pm
Location: Toronto, Canada

Post by webcan »

Thank you!

That seems to have worked.

Weird that it worked in the older version of PHP without problem though!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Also, use imagecopyresampled() rather than imagecopyresized() if you have GD2. imagecopyresampled() actually resamples the image so you get a much smoother, cleaner looking thumbnail.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply