Users upload images to a website and I store them in a folder. I also need to make a thumbnail, so I resize the image and put it in a different folder. Every so often, a thumbnail loses it color. It turns sort of blue and looks bad. I don't know why this happens. Any help greatly appreciated. Here is my relevant code:
The $image variable is a path to the uploaded image.
$new_width and $new_height are the dimensions I want for the new thumbnail.
$adid is just a number to use in naming the new image
I think everything else should be clear:
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$src = ImageCreateFromJpeg($image);
$dst = ImageCreate($new_width,$new_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,$new_width,$new_height,$width,$height);
$newDirectory = "gfx/images/";
$newFilename = $newDirectory . $adid . ".jpg";
imagejpeg($dst, $newFilename, 75);
ImageDestroy($src);
ImageDestroy($dst);
Thanks for any insights into what I may be doing wrong.
Mary Helen Fein
resize corrupts image, turns it blue
Moderator: General Moderators
Re: resize corrupts image, turns it blue
Try using imagecreatetruecolor instead of imagecreate.
Re: resize corrupts image, turns it blue
I tried imagecreatetruecolor, but I got a bunch of warnings, so I backed off. I will try again. Can you explain what it does differently from the command I am using, ImageCreate? I would greatly appreciate that as the doc you linked to is not clear.
Re: resize corrupts image, turns it blue
Truecolor images are more accurate than palette images. Like comparing GIFs with PNGs.
I don't really know - just try it.
I don't really know - just try it.
Re: resize corrupts image, turns it blue
I tried it again and it worked.
Thanks very much for the idea!
MH
Thanks very much for the idea!
MH
Re: resize corrupts image, turns it blue
Just because I'm an utter pedant and have to "correct" everything on here ... PNGs are a bit more complicated than that. They can be 8 bit (palette based) like a GIF, or 24 bit (3 8 bit channels like a JPEG, with a transparent colour like a GIF), or 32 bit (3 8 bit channels with an 8 bit alpha channel). imagepng() in PHP will create an 8 bit palette based image if the GD resource is 8 bit too (created with imagecreate(), or imagegif(), or imagepng() with an existing 8 bit image), or a 32 bit PNG if the GD resource is a true colour image.tasairis wrote:Truecolor images are more accurate than palette images. Like comparing GIFs with PNGs.
Re: resize corrupts image, turns it blue
Yeah... I'll have to concede that to you. I didn't really know what I was saying, I think it was more like an analogy than a comparison.onion2k wrote:Just because I'm an utter pedant and have to "correct" everything on here ... PNGs are a bit more complicated than that. They can be 8 bit (palette based) like a GIF, or 24 bit (3 8 bit channels like a JPEG, with a transparent colour like a GIF), or 32 bit (3 8 bit channels with an 8 bit alpha channel). imagepng() in PHP will create an 8 bit palette based image if the GD resource is 8 bit too (created with imagecreate(), or imagegif(), or imagepng() with an existing 8 bit image), or a 32 bit PNG if the GD resource is a true colour image.tasairis wrote:Truecolor images are more accurate than palette images. Like comparing GIFs with PNGs.
But I think I understand it now, so thanks.
Re: resize corrupts image, turns it blue
jedi mod,
Thanks for your clarification...
mh
Thanks for your clarification...
mh