Discussion:
jpg quality question with imagemagick and Gimp
blau
2010-09-13 13:55:18 UTC
Permalink
If I convert an image to jpg with a given quality of 85% I get this result:

convert -quality 85 in.jpg out.jpg

in.jpg: 174296 bytes
out.jpg: 150262

If I do it with Gimp, 85% quality, the resulting size is much smaller.

out.jpg 38650

The output quality of Gimp in this case is ok for me. I am looking for
size (bytes) reduction.

How can I get the same result with imagemagick (convert, mogrify)?

blau
Bob Meetin
2010-09-13 14:37:03 UTC
Permalink
Post by blau
convert -quality 85 in.jpg out.jpg
in.jpg: 174296 bytes
out.jpg: 150262
If I do it with Gimp, 85% quality, the resulting size is much smaller.
out.jpg 38650
The output quality of Gimp in this case is ok for me. I am looking for
size (bytes) reduction.
How can I get the same result with imagemagick (convert, mogrify)?
blau
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
Add -strip option

convert image.jpg -resize 480 -quality 85 -strip newimage.jpg
--
Bob Meetin
dotted i
303-926-0167 (home/business)
www.dottedi.biz/blog.php
Fred Weinhaus
2010-09-13 16:47:07 UTC
Permalink
Just use a lower quality value in IM. Quality can be different in
different programs.

Another issue is the compile Q level of IM. If you are running Q16
IM, then try adding -depth 8. That will lower the file size in IM,
too.
Post by blau
How can I get the same result with imagemagick (convert, mogrify)?
Fred Weinhaus
2010-09-13 16:50:36 UTC
Permalink
Just use a lower quality value in IM. Quality can be different in
different programs.

Another issue is the compile Q level of IM. If you are running Q16
IM, then try adding -depth 8. That will lower the file size in IM,
too.

Other factors such as profiles and other header information can
contribute also. So as Bob Meetin said, you can also add -strip to
remove those.

We don't know what you have done in GIMP or what GIMP does by itself.
So it is hard to say exactly what to do.
Post by blau
How can I get the same result with imagemagick (convert, mogrify)?
Bob Meetin
2010-09-13 21:08:36 UTC
Permalink
Post by Fred Weinhaus
Just use a lower quality value in IM. Quality can be different in
different programs.
Another issue is the compile Q level of IM. If you are running Q16
IM, then try adding -depth 8. That will lower the file size in IM,
too.
Other factors such as profiles and other header information can
contribute also. So as Bob Meetin said, you can also add -strip to
remove those.
We don't know what you have done in GIMP or what GIMP does by itself.
So it is hard to say exactly what to do.
Post by blau
How can I get the same result with imagemagick (convert, mogrify)
With GIMP when you go to save you get a slightly different dialogue if
you are saving .jpg (quality in percent) or png. If you want to save
PNG-8 vs PNG-24 you have to go slightly out of your way before you opt
to save. IM is slightly easier in both respects. It is many times
faster to use IM to run a series of comparative tests of, say, 30%, 40%,
50% ... 100% quality if you wanted to do that. Different programs -
different needs - different purposes.
blau
2010-09-14 07:56:03 UTC
Permalink
Post by Bob Meetin
It is many times
faster to use IM to run a series of comparative tests of, say, 30%, 40%,
50% ... 100% quality if you wanted to do that. Different programs -
different needs - different purposes.
Thank you Bob and Fred for your replies. I am doing some test using
several combinations of -quality -strip -depth.

IM is fast on the cli and that's the reason I want to use it.

The biggest size factor seems -quality, so far.

blau
Bob Meetin
2010-09-14 13:59:31 UTC
Permalink
I got real curious last night, ran a bunch of simple tests using the
same raw 3mb jpg. In the first test all I did was to add -strip and
rename the file. All the other including resizing it to 600 px wide. I
used combinations -quality, -strip and -depth. Some of the -quality
settings were almost pointless but I did them just because it's so
easy. Adding -strip seemed to be the biggest gain.

If you're using the image on the internet, somewhere between 70-80%
quality is typically 'good enough' in my opinion. Most people are not
very discerning in quality and the differences with higher quality are
so subtle that you may need to sit there with images side by side to
tell them apart. Image content is a big factor. On rare occasions
you'll see some that can live with 50%. I say this speaking as an
x-photographer who used to shoot with both 2 1/4 and 4x5 (film size)
formats.

ls -l | awk -F" " '{print $5, $8}'

216774 jensen.jpg
165523 jensen-strip.jpg
75167 jensen-s600.jpg
35269 jensen-s600-strip.jpg
3005 jensen-s600-strip-q1.jpg
6124 jensen-s600-strip-q10.jpg
9927 jensen-s600-strip-q20.jpg
13280 jensen-s600-strip-q30.jpg
15998 jensen-s600-strip-q40.jpg
18751 jensen-s600-strip-q50.jpg
21787 jensen-s600-strip-q60.jpg
26459 jensen-s600-strip-q70.jpg
29416 jensen-s600-strip-q75.jpg
33943 jensen-s600-strip-q80.jpg
40697 jensen-s600-strip-q85-d24.jpg
40665 jensen-s600-strip-q85-d8.jpg
40697 jensen-s600-strip-q85.jpg
52159 jensen-s600-strip-q90.jpg
77718 jensen-s600-strip-q95.jpg
183633 jensen-s600-strip-q100.jpg

Not knowing how the compression works, what I really find curious is
that when using -strip and a quality around 80% or above, the size is
about the same size or larger than -strip alone. To me it would make
sense that the following 2 commands produce the same result:

convert jensen.jpg -resize 600 -strip jensen-s600-strip-q100.jpg (by
ignoring quality isn't 100% assumed?)
convert jensen.jpg -resize 600 -quality 100 -strip
jensen-s600-strip-q100.jpg

-q 1 has the effect of a mind altering experience!

-Bob
blau
2010-09-14 14:39:56 UTC
Permalink
Post by Bob Meetin
Adding -strip seemed to be the biggest gain.
Yes
Post by Bob Meetin
If you're using the image on the internet, somewhere between 70-80%
quality is typically 'good enough' in my opinion.
Yes, on the web, 80-85% is a good tradeoff for quality and loading speed
imho. At least on the pages I am working now.
Post by Bob Meetin
216774 jensen.jpg
165523 jensen-strip.jpg
75167 jensen-s600.jpg
35269 jensen-s600-strip.jpg
3005 jensen-s600-strip-q1.jpg
6124 jensen-s600-strip-q10.jpg
9927 jensen-s600-strip-q20.jpg
13280 jensen-s600-strip-q30.jpg
15998 jensen-s600-strip-q40.jpg
18751 jensen-s600-strip-q50.jpg
21787 jensen-s600-strip-q60.jpg
26459 jensen-s600-strip-q70.jpg
29416 jensen-s600-strip-q75.jpg
33943 jensen-s600-strip-q80.jpg
40697 jensen-s600-strip-q85-d24.jpg
40665 jensen-s600-strip-q85-d8.jpg
40697 jensen-s600-strip-q85.jpg
52159 jensen-s600-strip-q90.jpg
77718 jensen-s600-strip-q95.jpg
183633 jensen-s600-strip-q100.jpg
I'll keep this list for future reference :-)
Post by Bob Meetin
-q 1 has the effect of a mind altering experience!
Very fun indeed!

blau
Mikolaj Machowski
2010-09-14 17:52:55 UTC
Permalink
Post by Bob Meetin
Not knowing how the compression works, what I really find curious is
that when using -strip and a quality around 80% or above, the size is
about the same size or larger than -strip alone. To me it would make
convert jensen.jpg -resize 600 -strip jensen-s600-strip-q100.jpg (by
ignoring quality isn't 100% assumed?)
No. Default quality is somewhat strange. From options page:

The default is to use the estimate quality of your input image otherwise 92.

Few years ago it was 75. I suppose change was introduced partially because IM
doesn't support lossless basic operations and increase in default quality
should counter negative effects of repeated rotation, flips, etc.

To improve quality of resize use "-sampling-factor 1x1". It will slightly
increase image size but significantly increase look of edges in output jpg.

m.
Fred Weinhaus
2010-09-15 00:24:09 UTC
Permalink
The default is to estimate the image quality or use 92 if it cannot
make a good estimate. Therefore, below, you have estimated quality in
the first and used quality=100 in the second.

Also you will be more efficient if you use -strip right after the
input, so those things don't get passed to the resized image.
Moreover, you will be even more efficient if you use -thumbnail
rather than -strip and -resize.
Post by Bob Meetin
To me it would make
convert jensen.jpg -resize 600 -strip jensen-s600-strip-q100.jpg (by
ignoring quality isn't 100% assumed?)
convert jensen.jpg -resize 600 -quality 100 -strip
jensen-s600-strip-q100.jpg
Bob Meetin
2010-09-15 15:10:53 UTC
Permalink
Post by Fred Weinhaus
The default is to estimate the image quality or use 92 if it cannot
make a good estimate. Therefore, below, you have estimated quality in
the first and used quality=100 in the second.
Also you will be more efficient if you use -strip right after the
input, so those things don't get passed to the resized image.
Moreover, you will be even more efficient if you use -thumbnail
rather than -strip and -resize.
216774 jensen.jpg
75167 jensen-s600.jpg
35269 jensen-s600-strip.jpg
29416 jensen-s600-strip-q75.jpg
35269 jensen-s600.thumb.jpg
29289 jensen-s600.thumb-q75.jpg

I added 2 more test images to the list. If you care to compare, visit
www.dottedi.biz/images/im-image_processing_tests. I'll add a
readme/whatidid doc if anyone requests. And maybe replace the pictures
later.

Loading...