开发者

Get compression ratio of image

I use LibJPEG to read JPEG compressed images. Is there a way to get the current compression ratio of the unchang开发者_如何学Goed image?


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.


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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜