Page 1 of 1

Retrieve JPEG quality?

Posted: Mon Feb 05, 2007 12:16 am
by abeall
I'm uploading images via POST, and resizing them then storing to the file system or a database. I would like to resize JPEGs(and PNGs and GIFs for that matter) in such a way that quality settings do not change -- neither decrease, or increased as it would not help, since the original was already lower quality. I haven't found a way to retrieve JPEG compression quality, or PNG/GIF data. How would this be done?

Posted: Mon Feb 05, 2007 2:18 am
by alex.barylski
You can look into the GD API:

http://ca3.php.net/manual/en/ref.image.php

As for not changing a JPEG quality when reducing it's size? I don't think thats possible...

JPEG uses lossy compression...so you actually loose raw data in favour of smaller files....however you can likely control the quality setting which dictates how *much* data is lost in resizing, etc...

Regardless of the format though, you always loose quality when you resize an image...it's really only the percentage of quality you can optionally specify with files like JPEG.

Posted: Mon Feb 05, 2007 2:21 am
by onion2k
GIF and PNG don't have a quality setting. You can control the colors in the palette, but keeping that the same when you're resizing the image will make them look absolutely terrible. JPEGs don't strictly have a setting either. You can set the quality of the image when it's being encoded, but that's really a value for the encoder rather than the output image. There's no reliable way to tell what setting was used.
Hockey wrote:it's really only the percentage of quality you can optionally specify with files like JPEG.
Pedantic note: The JPEG quality value is not a percentage. It's a value between 1 and 100. ;)

Posted: Mon Feb 05, 2007 2:24 am
by abeall
Thanks, both, will chew on this.

Posted: Mon Feb 05, 2007 2:47 am
by alex.barylski
onion2k wrote:GIF and PNG don't have a quality setting. You can control the colors in the palette, but keeping that the same when you're resizing the image will make them look absolutely terrible. JPEGs don't strictly have a setting either. You can set the quality of the image when it's being encoded, but that's really a value for the encoder rather than the output image. There's no reliable way to tell what setting was used.
Hockey wrote:it's really only the percentage of quality you can optionally specify with files like JPEG.
Pedantic note: The JPEG quality value is not a percentage. It's a value between 1 and 100. ;)
Fair enough :P

It's not like choosing 0% results in a totally blank image so in that regard you are correct, but:
dictionary.com wrote:A fraction or ratio with 100 understood as the denominator; for example, 0.98 equals a percentage of 98.