Retrieve JPEG quality?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Retrieve JPEG quality?

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

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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. ;)
Last edited by onion2k on Mon Feb 05, 2007 2:26 am, edited 1 time in total.
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Post by abeall »

Thanks, both, will chew on this.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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.
Post Reply