Low Quality Image Placeholder Generation

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
sabyamon
Posts: 10
Joined: 2019-03-07T12:34:50-07:00
Authentication code: 1152

Low Quality Image Placeholder Generation

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

Re: Low Quality Image Placeholder Generation

Post 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
sabyamon
Posts: 10
Joined: 2019-03-07T12:34:50-07:00
Authentication code: 1152

Re: Low Quality Image Placeholder Generation

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

Re: Low Quality Image Placeholder Generation

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

Re: Low Quality Image Placeholder Generation

Post 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.
Post Reply