+3 votes
242 views
How to get the quality of a JPG image or its compression level

in Guides by (552k points)
reopened | 242 views

1 Answer

+4 votes
Best answer

How to get the quality of a JPG image or its compression level.
Considerations when interpreting the quality of a JPG image.

It is usual to download images that we find on the internet to include in our articles or documents. Many of these images are in JPG format, which allows us to establish a quality level between 0 and 100 or compression level . The objective of this tutorial is how to find out the quality of a JPG image and thus determine its compression level .

image

When we talk about the best program to optimize images , we dedicate a section to talk about images in JPG format, which I recommend reading. What we should be clear about is that the JPG format is a format with losses and every time we save an image in this format we are losing quality .

How to get the quality of a JPG image or its compression level.

As we said at the beginning, when we save an image in JPG format we can set the quality with a number between 0 and 100. In some programs this parameter is referred to as compression level, but it is usual to designate it as quality.

When we download an image in JPG format, there is no direct way to find out its quality or compression level. The format does not save this information, although it is true that some programs add this information in the image metadata , it is not usual.

Despite all this, there is a method to find out the quality parameter of a JPG, for which we will use the free and cross-platform ImageMagick software. Within the ImageMagick package we will find the identify program, which allows us to obtain detailed information of an image.

To find out the quality of a JPG, we execute the following command from the command line :

identify -format '%Q' laimagen.jpg

image

We see that it will show us the quality number on the screen, represented by its value.

Considerations when interpreting the quality of a JPG image.

We must be clear that the overall quality of a JPG file does not depend solely on the established quality parameter, but other parameters such as chroma subsampling, quantization tables, etc. are involved. With this, what I want to show you, is that the quality of the same JPG image can vary if we save it with different programs, even if we use the same quality parameter.

To demonstrate it you can see the following image, which in both cases has been saved with a quality parameter 60, but the first image has been saved with GIMP and the second with Photoshop.

image

If you look, we can see that the image saved with Photoshop offers higher overall quality than the one saved with GIMP. We also have to consider that the image saved with Photoshop has a size of 15.5KB while the image saved with GIMP 9.91KB. But this difference in size has an explanation and is that the quality chosen in Photoshop of 60, actually corresponds to a quality parameter 86.

Then I leave the complete data of the two images compared:

C:\ImageMagick-7.0.5-0-portable>identify -verbose test_gimp.jpg
Image: test_gimp.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 480x220+0+0
  Resolution: 72x72
  Print size: 6.66667x3.05556
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 105600
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 192.338 (0.754266)
      standard deviation: 40.7007 (0.159611)
      kurtosis: -0.59641
      skewness: 0.193754
      entropy: 0.508844
    Green:
      min: 45 (0.176471)
      max: 255 (1)
      mean: 157.433 (0.617385)
      standard deviation: 48.0412 (0.188397)
      kurtosis: -0.460929
      skewness: 0.541649
      entropy: 0.547715
    Blue:
      min: 18 (0.0705882)
      max: 255 (1)
      mean: 177.084 (0.694446)
      standard deviation: 46.2831 (0.181502)
      kurtosis: 0.581174
      skewness: -1.11279
      entropy: 0.557997
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 175.618 (0.688699)
      standard deviation: 47.325 (0.185588)
      kurtosis: -0.342889
      skewness: -0.226262
      entropy: 0.538186
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: JPEG
  Intensity: Undefined
  Compose: Over
  Page geometry: 480x220+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 60
  Orientation: Undefined
  Properties:
    date:create: 2017-03-02T16:27:01+01:00
    date:modify: 2017-03-02T16:27:01+01:00
    jpeg:colorspace: 2
    jpeg:sampling-factor: 1x1,1x1,1x1
    signature: a0ecd9fc0fe16532fd6a71e4055d410a86ff90e555dcc8dbb213c9ab7364a633
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 9.91KB
  Number pixels: 106K
  Pixels per second: 17.6MB
  User time: 0.016u
  Elapsed time: 0:01.006
  Version: ImageMagick 7.0.5-0 Q16 x64 2017-02-20 http://www.imagemagick.org
C:\ImageMagick-7.0.5-0-portable>identify -verbose test_photoshop.jpg
Image: test_photoshop.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 480x220+0+0
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 105600
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 192.711 (0.755728)
      standard deviation: 40.5036 (0.158838)
      kurtosis: -0.461151
      skewness: 0.153411
      entropy: 0.522216
    Green:
      min: 41 (0.160784)
      max: 255 (1)
      mean: 157.996 (0.619592)
      standard deviation: 48.1356 (0.188767)
      kurtosis: -0.460604
      skewness: 0.523291
      entropy: 0.545854
    Blue:
      min: 29 (0.113725)
      max: 255 (1)
      mean: 177.555 (0.696293)
      standard deviation: 46.9984 (0.184308)
      kurtosis: 0.520238
      skewness: -1.11799
      entropy: 0.556904
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 176.087 (0.690538)
      standard deviation: 47.512 (0.186322)
      kurtosis: -0.324822
      skewness: -0.258086
      entropy: 0.541658
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 480x220+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 86
  Orientation: Undefined
  Properties:
    date:create: 2017-03-02T16:28:10+01:00
    date:modify: 2017-03-02T16:28:11+01:00
    jpeg:colorspace: 2
    jpeg:sampling-factor: 1x1,1x1,1x1
    signature: 7e7c7e918d7d2f7e8fd340f7c775f1ff72ac43b6c7870446a1c41311209b80b0
  Profiles:
    Profile-app12: 15 bytes
    Profile-exif: 22 bytes
    Profile-xmp: 766 bytes
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 15.5KB
  Number pixels: 106K
  Pixels per second: 26.4MB
  User time: 0.000u
  Elapsed time: 0:01.003
  Version: ImageMagick 7.0.5-0 Q16 x64 2017-02-20 http://www.imagemagick.org

Finally, I also want to clarify that if a JPG image that has been saved with the quality parameter with a value of 80, if we save it again with a quality parameter 90, the quality will not improve . This is because the JPG format is a lossy format.

For the above reason it is so important to know the quality of a JPG image that we download from the internet, so as not to save it with higher quality than necessary and not waste space.


by (3.5m points)

Related questions

+5 votes
1 answer
asked Aug 10, 2019 in Guides by backtothefuture (552k points) | 1.9k views
+5 votes
1 answer
+3 votes
1 answer
asked Aug 9, 2019 in Guides by backtothefuture (552k points) | 257 views
+4 votes
4 answers
asked Aug 9, 2019 in Guides by backtothefuture (552k points) | 74.7k views
+3 votes
1 answer
asked Aug 9, 2019 in Guides by backtothefuture (552k points) | 225 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users