Page 1 of 1

Image size after convert -composite

Posted: 2010-03-22T02:07:47-07:00
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

Re: Image size after convert -composite

Posted: 2010-03-22T02:18:53-07:00
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. :?

Re: Image size after convert -composite

Posted: 2010-03-22T03:21:55-07:00
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.

Re: Image size after convert -composite

Posted: 2010-03-22T03:59:12-07:00
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

Re: Image size after convert -composite

Posted: 2010-03-22T04:29:39-07:00
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.

Re: Image size after convert -composite

Posted: 2010-03-22T04:36:58-07:00
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".