Can I tell the quality level of JPEG?

This is really a two-part question, since I do not quite understand how it all works:

My situation: I am writing a web application that allows the user to upload an image. My application then resizes to something displayed (ex: 640x480-ish) and saves the file for later use.

My questions:

  • Given an arbitrary JPEG file, is it possible to specify a quality level so that I can use the same quality when saving a modified image?
  • Does it even matter? Should I keep all the images at a decent level (for example, 75-80), regardless of the original quality?

I'm not so sure about this because, as I understand it: (let's take an extreme example), if someone had a 5 megapixel image saved at quality 0, it would be blocky. By reducing the image size to 640x480, the blocking will be smoothed out and barely noticeable ... until I save it with a quality of 0 again ...

At the other end of the spectrum, if there were an 800x600 image with q = 0, resizing to 640x480 would not change the fact that it looks like complete crap, so saving with q = 80 would be redundant.

Am I even close?

I use the GD2 library in PHP if this is useful

+48
image-processing jpeg image-compression
Jan 08 '10 at 1:50
source share
10 answers
  • JPEG is a lossy format. Each time you save the same image in JPEG format, regardless of the quality level, you reduce the actual image quality. Therefore, even if you received a quality level from a file, you would not be able to maintain the same quality when saving JPEG again (even with quality = 100).

  • You should save your JPEG as high quality as you can afford in terms of file size. Or use a lossless format like PNG.

Poor quality JPEG files don't just get more blocky. Instead, the color depth decreases, and the details of the image sections are deleted. You cannot rely on lower quality images that are blocky and look normal with smaller sizes.

According to the JFIF specification, the quality number (0-100) of the image is saved, it is not stored in the image header, although the horizontal and vertical pixel density is preserved.

+22
Jan 08 '10 at 1:57
source share

You can view the compression level using ImageMagick. Download and installation instructions can be found on the official website.

After installing it, run the following command at a command prompt:

identify -format '%Q' yourimage.jpg 

And you should get a value from 0 (low quality, small file size) to 100 (high quality, large file size).

The source of information

+60
Aug 22 '13 at 10:35 on
source share

Jpeg compression algorithm has some parameters that affect the image quality of the result.

One such parameter is quantization tables, which determine how many bits will be used for each coefficient. Different programs use different validation tables.

Some programs allow the user to set the quality level to 0-100. But the total number of this number is not. An image made using Photoshop with 60% quality takes 46 KB, and an image made using GIMP takes only 26 KB.

Quantization tables are also different.

There are other options such as subsampling method, dct, etc.

Thus, you cannot describe all of them with one quality level number, and you cannot compare the quality of jpeg images by one number. But you can create a quantity like photoshop or gimp that will describe the trade-off between size in quality.

Additional information: http://patrakov.blogspot.com/2008/12/jpeg-quality-is-meaningless-number.html

A common practice is that you resize the image to the appropriate size and apply jpeg after that. In this case, large and medium-sized images will have the same size and quality.

+8
Jan 11 '10 at 17:38
source share

For future visitors, checking the quality of a given jpeg, you can simply use the imagemagick tool:

 $> identify -format '%Q' filename.jpg 92% 
+7
Apr 02 '15 at 17:35
source share

So basically you are worried about two cases:

  • If the incoming image is of a too high quality level, incorrect space may be required. Therefore, you may need to, for example, reduce the incoming q = 99 to q = 85.

  • If the incoming image is too low in quality, it can be a waste of time to improve its quality. Except that an image that has been discarded with a large amount of data will not magically take up more space with higher quality - locked images will compress very well even with high quality settings. Therefore, in my opinion, it is quite normal to raise incoming q = 1 by q = 85.

From this, I would think that just forcing a decent quality setting is a perfectly acceptable thing.

+3
Jan 11 '10 at 18:39
source share

Each new file save will further reduce the overall quality, using higher quality values, you will save more images. Regardless of the quality of the original image.

+2
Jan 08 '10 at 1:56
source share

Here is the formula I found to work well:

  • jpg100size (size should not exceed in bytes for quality 98-100%) = width * height /1.7

  • jpgxsize = jpg100size * x (x = percentage, e.g. 0.65)

therefore, you can use them to find out statistically what quality you last saved. if you want to get it to say 65% ​​quality, and if you want to avoid re-sampling, you must first compare the size to make sure it is not too low, and only then reduce the quality

+2
Oct 22 '14 at 14:13
source share

As there have already been two answers, using identify , here is one that also displays the file name (for scanning multiple files at the same time) :

If you want to have simple filename: quality output for use on multiple images, you can use

 identify -format '%f: %Q' * 

to show file name + compression of all files in the current directory.

+2
May 09 '17 at 9:20 a.m.
source share

If you save JPEG using the same software that originally created it using the same settings, you will find that the damage is minimized - the algorithm will tend to throw out the same information that it threw for the first time. I don’t think there is a way to find out which level was selected simply by looking at the file; even if you could, different software almost guarantees different parameters and rounding, which makes the match almost impossible.

+1
Jan 08 '10 at 2:09
source share

This may be a dumb question, but why should you worry about micromanagement of document quality? I believe that if you use ImageMagick for conversion, then it will better manage JPEG quality for you. http://www.php.net/manual/en/intro.imagick.php

+1
Jan 11 '10 at 18:32
source share



All Articles