views:

18

answers:

1

Hi all,

I'm developing a web-to-print, poster printing application.

I'm considering using PHP to crop user-uploaded images, and we will ultimately print the PHP-cropped image.

My concern is there will be a difference in 'quality' between the original user uploaded image, and image after it is cropped by PHP.

Will PHP affect the quality of the image when handling it? Or does it preserve the image's quality and simply crop the relevant area?

Many thanks,

BK

+1  A: 

JPEG is lossy compression. A bit of oversimplification, but it works by analyzing pixels around other pixels to see how similar they are. Not every pixel is stored, and that means it isn't possible to simply chop bytes out of the image data to perform the crop. If you are outputting JPEG, you will be re-compressing an already compressed image, and you will have some loss in quality. However, if you crop the image and your output is a non-lossy format, then you will not have loss of quality.

To be clear, the loss of the quality isn't in the crop operation. It is in the way the image is compressed itself. If the source image is compressed with JPEG, quality has already been lost. When you crop that image, you aren't losing anything more, but if you were to output JPEG again afterwards, this would require a re-compression, and thus more loss.

So in the end, make your final output PNG or something non-lossy and you have nothing to worry about.

Brad
Thanks Brad. Answered my question!
kaese
Happy to help! You should mark it as the accepted answer then.
Brad
Actually, if you crop the JPEG at a multiple of the block size specialized software can save the JPEG without reencoding it.
Georg
Good point Georg. While I doubt it applies here, some quick Googling turned up some code some guy wrote on the PHP documentation comments for reading JPEG manually. In there, he figures out the block size. It might be a good place to start. http://www.php.net/manual/en/function.getimagesize.php#88793
Brad