Retrieve JPEG quality?
Moderator: General Moderators
Retrieve JPEG quality?
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?
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
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.
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.
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.

Pedantic note: The JPEG quality value is not a percentage. It's a value between 1 and 100.Hockey wrote:it's really only the percentage of quality you can optionally specify with files like JPEG.
Last edited by onion2k on Mon Feb 05, 2007 2:26 am, edited 1 time in total.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Fair enoughonion2k 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.Pedantic note: The JPEG quality value is not a percentage. It's a value between 1 and 100.Hockey wrote:it's really only the percentage of quality you can optionally specify with files like JPEG.
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.