Page 1 of 1

How to reduce size of jpg images

Posted: 2012-02-06T08:25:26-07:00
by mabian
Hello,

I am converting eps images to jpg using the convert command, like this:

convert.exe -format "jpg" -density 72x72 -quality 91 -resize 130x130 -background white -flatten -colorspace RGB "<source eps path>" "<destination jpg path>"

The conversion works well, but I am noticing that the files created by convert are sometimes much larger in comparison with the same jpg saved by Illustrator, Photoshop or Image Alchemy.
For example, I have one file which is around 32kb, created in Image Alchemy; the same file is around 580Kb when created by convert.

The compared files have, according to identify command:

- Same quality (91)
- Same DPI (72x72)
- Same pixel size (actually, at most one pixel difference)

Of course, the files are created starting from the very same EPS, and there's no (clear) visual difference between the images.

So, what can be the cause of this difference, can I use the identify command to detect them and what parameters can I tweak in convert to get the same conversion settings?

Thank you in advance,
Mario

Re: How to reduce size of jpg images

Posted: 2012-02-06T12:08:38-07:00
by fmw42
I believe that Anthony has mentioned before that PS uses very tuned custom JPG compression tables where as IM use libjpg to do its work. The only way to reduce the size in IM, that I know, is to reduce the -quality factor.

Re: How to reduce size of jpg images

Posted: 2012-02-06T19:10:13-07:00
by glennrp
Try the "-strip" option. You are probably carrying an ICC profile, EXIF profile, or maybe an embedded thumbnail, and -strip will get rid of those.
If you are curious about what's actually in the image besides the pixel data, run "identify -verbose file.jpg".

Re: How to reduce size of jpg images

Posted: 2012-02-06T19:14:12-07:00
by glennrp
glennrp wrote:Try the "-strip" option. You are probably carrying an ICC profile, EXIF profile, or maybe an embedded thumbnail, and -strip will get rid of those.
If you are curious about what's actually in the image besides the pixel data, run "identify -verbose file.jpg".
Oops, sorry, I didn't realize you were not starting with a JPG. So my suggestion might not help. All the same, I wouldn't expect a 131x131 JPEG output
to be 500kb if it didn't contain more than just the image.

Re: How to reduce size of jpg images

Posted: 2012-02-06T23:24:25-07:00
by mabian
Actually I think you could be on something: the identify verbose shows exif and other data; will try with -strip and check what happens.

Thanks!

- Mario

Re: How to reduce size of jpg images

Posted: 2012-02-07T00:29:06-07:00
by whugemann
I don't think that the -strip option will show much of the desired effect, because this data shouldn't be larger than a few kB, even if it contains a TIFF preview, which I doubt.

AFAIK, "quality" is no precisely definded term for the encoding of JPEG images, so different programs might understand slightly different things by a certain quality setting. Furthermore, the JPEG encoding process is not precisely defined (the standard only defining the decoding process) and thus leaves room for optimisations. To my experience, Photoshop does a pretty efficient job in JPEG encoding.

If your JPEGs must be limited in size, try the -define jpeg:extent=40kb setting (of course with some size of your choice). I think that it will automatically strip off any superfluous data and it will take somewhat longer for the encoding. But it works much like the JPEG encoding in digital cameras, which is heading for a certain file size rather than a certain quality.

Re: How to reduce size of jpg images

Posted: 2012-02-07T01:47:27-07:00
by mabian
Well, the strip command made a huge difference: a 500+Kb jpg became 5kb after simply adding the -strip option!

As far as I know, the EPS files contain an 8 bit (tiff?) preview, anyway now I'm getting even smaller files than the original jpgs I was using as comparison.

It seems there's no appreciable difference visually, I think I found my ticket.

Now the only little problem left is that, even adding a -comment option after the -strip one, the comment isn't written in the image metadata; maybe the -strip option overrides -comment?

Thank you so much.

- Mario

Re: How to reduce size of jpg images

Posted: 2012-02-07T10:58:40-07:00
by fmw42
Now the only little problem left is that, even adding a -comment option after the -strip one, the comment isn't written in the image metadata; maybe the -strip option overrides -comment?
try

convert yourimage -set comment "yourcomment" ...

or

try

convert -comment "yourcomment" yourimage ....

Re: How to reduce size of jpg images

Posted: 2012-02-07T22:14:57-07:00
by anthony
-comment will only add comments to images as they are being read in.

-set comment will set comments on images already in memory (even if previous comments have been stripped).

See Image Attributes and Metadata
http://www.imagemagick.org/Usage/basics/#settings

Also Labelling of Images (comments are just another type of label)
http://www.imagemagick.org/Usage/montage/#label