Get compression ratio of image

◇◆丶佛笑我妖孽 提交于 2019-12-11 03:05:40

问题


I use LibJPEG to read JPEG compressed images. Is there a way to get the current compression ratio of the unchanged image?


回答1:


Do you mean the encoding quality, usually a number 0-100?

That isn't stored - it's used as a guide for the image encode as to how accurate the waves should be, and it's then discarded. There's no field for it in any of the JFIF header structures. As far as I can see there's no formal definition of what this number means across encoders and so you can't precisely determine the effects of any given number anyway.




回答2:


The compression level must be stored somewhere if Photoshop saves the Jpeg. For years I have used Photoshop's Save As on a file as a method of detecting what compression level was used. In my experience it always suggests a compression level equal to that used on the current file. Note that you don't actually have to save it. Obviously this method is no good for lots of files, but surely is evidence that it must be stored there somewhere.




回答3:


if compression ratio, do you mean filesize relative

you may use identify -verbose from ImageMagick-6.7.5.6

For example:

identify -verbose 1.jpg
(...)
  Geometry: 607x800+0+0
  Resolution: 72x72
(...)
  Filesize: 143KB
  Number pixels: 486K

good

identify -verbose 2.jpg
  (...)
  Geometry: 1719x2377+0+0
  Resolution: 100x100
  (...)
  Filesize: 408KB
  Number pixels: 4.086M

bad

convert 2.jpg -resample 72x72 2c.jpg 
identify -verbose 2c.jpg
  Geometry: 1238x1711+0+0
  Resolution: 72x72

  Filesize: 272KB
  Number pixels: 2.118M

much better

http://www.imagemagick.org/script/command-line-options.php?#density talk about this subject and finish with "To resize the image so that it is the same size at a different resolution, use the -resample option"

I found also a tool to modify "jpeg quality factor". Jpegoptim - utility to optimize jpeg files. Provides lossless optimization (based on optimizing the Huffman tables) and "lossy" optimization based on setting maximum quality factor. http://www.kokkonen.net/tjko/projects.html

Hope help in something.




回答4:


Compression ratio = (uncompressed size) / (compressed size).

To get that automatically, download Irfanview, free image program for Windows, open your image with it and then from the go to Image -> Information -> You can see a lot of useful information there, among those are "Compression" and quality, size resolution colors etc. Now go to -> EXIF info -> Compression -> The number here is the compression ratio.

example: If the compression is 6, then the original file/image size was 6 times bigger than the compressed one (you are now viewing).



来源:https://stackoverflow.com/questions/4853851/get-compression-ratio-of-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!