Page 1 of 1

Low Quality Image Placeholder Generation

Posted: 2019-03-07T16:31:21-07:00
by sabyamon
Hi All,

I pretty new to Image Magick and working on a solution to create a low-quality placeholder image for any given image (jpeg/png/gif).
My main goal is to get a blurred image which will be of the same dimension of the original image but very very low sized.
Let's say a placeholder image of a 2400 × 1474px and 1MB JPEG image will be of the same dimension but the size of it will be less than 20kb(or even lesser). Also, it should be blurred to hide the pixel losses.

- Attaching the original JPEG and a generated placeholder JPEG (which looks good but needs more compression).
- Attaching the original PNG for which I am not able to get a decent blurred placeholder image with a size less than 20kb.

Commands that I have used -

Code: Select all

convert original.jpeg -quality 40 -blur 0x80 ph.jpeg
[0] - https://drive.google.com/open?id=1m9_uD ... vhwgMcq2CM


Image Magick Version - IM 6 and 7 (Need to support both)
OS Version - Mac OS - 10.13.3

Would really appreciate help in this.
Thanks,
Sabya

Re: Low Quality Image Placeholder Generation

Posted: 2019-03-07T17:18:44-07:00
by fmw42
You may be able to get your result down to 20KB for JPEG but not for PNG if you keep the original dimensions. This produces an image that is blurred but I can only get the file size down to 43 KB and the quality is 1. So I don't think you can get it much smaller with ImageMagick, unless you reduce the dimensions of the image. You could try one of the specialized jpeg compression tools. See https://imagemagick.org/Usage/formats/#jpg_non-im

Code: Select all

convert original.jpeg -blur 0x10 -define jpeg:extent=20KB result.jpg

Re: Low Quality Image Placeholder Generation

Posted: 2019-03-08T14:38:29-07:00
by sabyamon
Thanks fmw42.

I get it.
So, for a given png/jpeg image, if I always convert that to a jpeg and compress + blur it, can I get it to below 20kb?
What would my convert command look in that case?

I have tried jpeg:extent, but most of the times thats not bringing the size down to my expected size.

I am trying to understand if I can progressively work on an image using IM?
Like, convert the png/jpeg -> jpeg -> blur -> compress -> output/save the final jpeg

I have tried the following.

Code: Select all

convert original.png -blur 0x8 -quality 10 placeholder.jpeg

Code: Select all

convert original.jpeg -blur 0x8 -quality 10 placeholder.jpeg

Re: Low Quality Image Placeholder Generation

Posted: 2019-03-08T16:52:00-07:00
by fmw42
The jpeg:extent choses a -quality value to try to achieve your desired file size. In this case it chose as low a value as it could for JPG output, which was quality=1. It cannot go lower and it did not achieve your file size. So you never will be able to achieve that with ImageMagick, unless you reduce the dimension (WxH) of your image. Perhaps one of the non-Imagemagick JPG tools can do better.

There is no similar thing for PNG output. The only option you have for PNG is convert to JPG or reduce the dimensions (WxH) to achieve your desired output file size.

Re: Low Quality Image Placeholder Generation

Posted: 2019-03-08T20:37:52-07:00
by fmw42
Often you can further reduce the file size by adding -strip after reading the input file in order to remove all excess meta data. But in the case of the image above, it does not help.