Page 1 of 1

Php GD Question for Crop and resize

Posted: Wed Aug 04, 2010 4:24 am
by dharprog
Hi All,

I have a big question in my mind that, When we use cropping functionality on a re-sized image do we lose quality?

Suppose original image dimensions are 4500X4500 and when this gets uploaded we can not display this much size image on the webpage or webscreen. So we need to resize it to some 50% or 25% to provide the crop functionality on the image.

So because of this resize functionality on the original image do we lose the quality or it will be having perfect quality of the image?

When we upsample the image do we lose quality? if so what is the necessary step i need to take not to lose the quality of the image/picture?

Please kindly get me the guidance how to handle this issue.

Waiting for your reply.

Thanks and regards,
Dharprog

Re: Php GD Question for Crop and resize

Posted: Wed Aug 04, 2010 6:43 am
by requinix
Think about it. Just think about it for a second.

When you resize an image you go from X number of pixels to Y number of pixels:
- If X>Y (shrinking) then those X-Y pixels are lost. You cannot get them back. There is no Recycle Bin for pixels.
- If X<Y (enlarging) then you're creating Y-X pixels out of thin air. You aren't "undeleting" them from a previous image.

When shrinking you lose quality. Generally you get around this by manipulating the original image* and trying to combine multiple colors into one pixel. It can look good, but you've still lost quality.
When enlarging you gain fake quality, and if you enlarge too much then the larger image typically looks worse than the smaller original.

* And by this I mean manipulating the cropped image... Easy to misunderstand that, I know ;)

Re: Php GD Question for Crop and resize[Solved]

Posted: Wed Aug 04, 2010 7:34 am
by dharprog
tasairis wrote:Think about it. Just think about it for a second.

When you resize an image you go from X number of pixels to Y number of pixels:
- If X>Y (shrinking) then those X-Y pixels are lost. You cannot get them back. There is no Recycle Bin for pixels.
- If X<Y (enlarging) then you're creating Y-X pixels out of thin air. You aren't "undeleting" them from a previous image.

When shrinking you lose quality. Generally you get around this by manipulating the original image and trying to combine multiple colors into one pixel. It can look good, but you've still lost quality.
When enlarging you gain fake quality, and if you enlarge too much then the larger image typically looks worse than the smaller original.
This is absolutely true and found the solution how i can handle it now without losing any quality for cropping.

Thanks a lot.

Re: Php GD Question for Crop and resize

Posted: Wed Aug 04, 2010 10:19 am
by pickle
Cropping & resizing are different. Cropping means cutting out part of the picture. Resizing means keeping the entire picture, but changing the dimensions. Cropping will not lose you any quality, but you will lose part of the picture.

Resizing either up or down will always result in a loss of detail. Always. If you use imagecopyresampled() instead of imagecopyresized(), then the loss in quality will be much less. Basically exactly what ~tasairis said.

Re: Php GD Question for Crop and resize

Posted: Fri Aug 06, 2010 11:01 pm
by dharprog
Hi Pickle,

The difference is correct, And i will use imagcopyresized() as per your suggestion to not to lose the quality.

Thank you very much for valuable suggestion for both of you.

Thanks and regards,
Dharprog

Re: Php GD Question for Crop and resize

Posted: Fri Aug 06, 2010 11:21 pm
by requinix
1. imagecopyresampled will lose quality. What pickle said was that the loss in quality would be less, not zero.
2. If you're concerned about quality, don't use GD. It's good for quick-n-dirty tasks but isn't good for need-it-done-well tasks. Try ImageMagick instead.

Re: Php GD Question for Crop and resize

Posted: Sat Aug 07, 2010 1:33 am
by dharprog
tasairis wrote:1. imagecopyresampled will lose quality. What pickle said was that the loss in quality would be less, not zero.
2. If you're concerned about quality, don't use GD. It's good for quick-n-dirty tasks but isn't good for need-it-done-well tasks. Try ImageMagick instead.
Did you mean that, ImageMagick is more efficient than GD? And is this ImageMagick good quality results in image processing?

If it is so then i will be going working with ImageMagick for all the image processing tasks.

Thanks and regards,
Dharprog

Re: Php GD Question for Crop and resize

Posted: Sat Aug 07, 2010 5:13 am
by requinix
It's pointless (not to mention difficult) to compare "efficiency" between the two. ImageMagick is better than GD at everything I can think of, with the disadvantage that it doesn't come bundled with PHP so you have to install it yourself - on shared hosting that can be a problem.