Page 1 of 1
Additional JPG compression?
Posted: 2018-08-24T08:30:14-07:00
by ZakO12
Hi,
I need to resize a lot of images so I'm wanting to use the imagemagick command line, previously I've just used a website to do it for me (resizeimage.net). Problem is, the resulting image from imagemagick is significantly larger than if I use the site mentioned above:
Code: Select all
magick in.jpg -strip -quality 75 -interlace JPEG -resize x500 out.jpg
Resulting file from imagemagick is 86.8kb, if I use the site above the resulting image with the same dimensions / compression quality is 59.2kb with no noticeable difference in quality even while zoomed in to the image.
This is just one example using the source image (
https://steamcdn-a.akamaihd.net/steam/a ... 0x1080.jpg), in other cases the difference can be up to 3 times as large.
I've messed around with -sampling-factor and adding a tiny -gaussian-blur but even then it's still > 59.2kb and at a worse quality than the one the website produces.
Are there extra options I should be passing the imagemagick to reduce the file size further? Thanks in advance.
Re: Additional JPG compression?
Posted: 2018-08-24T09:20:45-07:00
by fmw42
Proper IM 7 syntax would be
Code: Select all
magick in.jpg -strip -resize x500 -interlace JPEG -quality 75 out.jpg
but that does not help make your results smaller. I would suggest that you just reduce the -quality value.
ImageMagick uses libjpeg to process JPG files. So this is a limitation of libjpeg and the q tables it uses.
Re: Additional JPG compression?
Posted: 2018-08-24T09:32:13-07:00
by ZakO12
Thanks for the reply, that website is using Imagemagick to process/compress the images too (same version as me) so it seems more to do with what options they're using rather than a libjpeg limitation?
Re: Additional JPG compression?
Posted: 2018-08-24T09:38:13-07:00
by fmw42
Are you sure they are not doing some further compression optimization using other tools following the ImageMagick processing. See
https://www.imagemagick.org/Usage/formats/#jpg_non-im, for example. Also they may have customized the q tables? Or they are using some other -quality value?
Re: Additional JPG compression?
Posted: 2018-08-24T09:44:10-07:00
by ZakO12
I'm not entirely sure, I'll try out some different tools, magick identify -verbose says their quality is 75, same as mine. Using -sampling-factor 4:2:0 gets me a little bit closer to their file size (70.5kb vs 59.2kb) but it's still quite a significant difference (I'm resizing 750,000 images).
Re: Additional JPG compression?
Posted: 2018-08-24T09:47:28-07:00
by fmw42
What is the other tool you are comparing to? Have you asked them if they are doing anything special apart from ImageMagick? They may be using some other jpeg library apart from libjpeg with ImageMagick.
Re: Additional JPG compression?
Posted: 2018-08-24T10:29:20-07:00
by ZakO12
Not sure what tool they use I was just using a website (resizeimage.net).
I think I was mistaken about them using ImageMagick though, I ran magick identify -verbose on their output image and assumed because the output said "Version: ImageMagick 7.0.8-10 Q16 x64 2018-08-14" that was the tool their site is using to create the image, but thinking about it now I assume that's actually just listing the imagemagick version I'm using to identify the image, doh!
This is a diff of the image compressed using their site (left) vs imagemagick (
https://www.diffchecker.com/Rm9QWfme)
I'll try contacting them to see what tools they actually use.
Re: Additional JPG compression?
Posted: 2018-08-24T11:16:03-07:00
by fmw42
The file on the left in your diff, does not show what quality level was used. So it could be smaller than 75.
Re: Additional JPG compression?
Posted: 2018-08-24T11:34:09-07:00
by ZakO12
It could, but the website explicitly lets you choose what quality level you want so I honestly doubt it is. The image artefacts look almost identical as a 75 quality imagemagick image too, if I turn down the imagemagick quality (i.e. 70) there's more artefacts than the one produced by the website.
Thanks for your replies anyway, I don't see a way to contact the owner of the site so I probably won't be able to find out what they use. I've ended up settling for 70 quality with 4:2:0 sampling-factor:
Code: Select all
magick in.jpg -strip -resize x500 -interlace JPEG -quality 70 -sampling-factor 4:2:0 -colorspace RGB out.jpg
Unfortunately the output is a few kb bigger (64.1kb vs 59.1kb) and quality is a bit worse but it's good enough.
Re: Additional JPG compression?
Posted: 2018-08-24T12:31:16-07:00
by snibgo
"-interlace JPEG" adds bytes to the file. Do you need this?
Do you need to start from jpeg inputs? Don't you have anything better?
Re: Additional JPG compression?
Posted: 2018-08-24T12:40:31-07:00
by ZakO12
"-interlace JPEG" reduces the file size for me? Source images are JPEGs (saved at 100% quality) I don't have anything better, they have been provided by other companies.
Code: Select all
magick in.jpg -strip -resize x500 -quality 70 -sampling-factor 4:2:0 out.jpg
= 65.6kb
Code: Select all
magick in.jpg -strip -interlace JPEG -resize x500 -quality 70 -sampling-factor 4:2:0 out.jpg
= 64.2kb