How to reduce size of jpg images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mabian
Posts: 6
Joined: 2012-02-03T03:14:50-07:00
Authentication code: 8675308

How to reduce size of jpg images

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to reduce size of jpg images

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How to reduce size of jpg images

Post 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".
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How to reduce size of jpg images

Post 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.
mabian
Posts: 6
Joined: 2012-02-03T03:14:50-07:00
Authentication code: 8675308

Re: How to reduce size of jpg images

Post 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
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to reduce size of jpg images

Post 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.
Wolfgang Hugemann
mabian
Posts: 6
Joined: 2012-02-03T03:14:50-07:00
Authentication code: 8675308

Re: How to reduce size of jpg images

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to reduce size of jpg images

Post 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 ....
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to reduce size of jpg images

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply