Image size after convert -composite

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
jaconat

Image size after convert -composite

Post by jaconat »

Hi

Can someone explain why the file size of a composite image increases so dramatically and how I can reduce the final file size without loss of quality?

I am running the following code,

Code: Select all

convert 'background.png' 'image.jpg' '[600x450]' -geometry +116+76 -composite 'newimage.png'
The file sizes are,
background.png - 43.6kb
image.jpg - 174.63kb
newimage.png - 603.15kb :shock: :shock: :shock:

I tried the -compress switch with no effect on output file size.

Thanks
jaconat

Re: Image size after convert -composite

Post by jaconat »

Just tried adding -quality 100 (**best** compression but slower) after the -composite switch but got a bigger file size of 839kb for newimage.png.

Now really confused. :?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image size after convert -composite

Post by snibgo »

One of your inputs is a jpeg. I suspect it is a photograph, and these don't compress so well in png format. (Partly because png is lossless, but mostly because png just isn't designed to compress photographs well).

If you save the result to jpg, you can probably get a much smaller file size.

"Quality" refers to quality of the image, so higher number give better quality but *lower* compression.
snibgo's IM pages: im.snibgo.com
jaconat

Re: Image size after convert -composite

Post by jaconat »

Thanks snibgo. Tried changing output image to jpg. newimage.jpg size is now 342kb (compared to 600+kb). Smaller than saving as a png but not as small as I expected.

Any other tips without an overall effect on quality? Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image size after convert -composite

Post by snibgo »

I think the default IM uses for saving jpegs is 85. Perhaps your input files don't warrant this, so you might try "-quality 50" or 25 or 10. (I often find that 50 is good enough for web work, and would expect 10 to be very small but horrble quality.)

I wish IM (and other tools) had an automatic facility to save files with lowest subjectively justifiable quality, but this is a Hard Problem. It might not be difficult for a tool to detect gross artifacts introduced by the lossy compression.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image size after convert -composite

Post by snibgo »

Hmm. Perhaps a script could use "-metric" to graph size versus quality setting, and find an optimum. I'll add this to my huge pile of "things to try when I can find the time".
snibgo's IM pages: im.snibgo.com
Post Reply