Page 1 of 1

PNG file grows dramatically when image size reduced

Posted: 2007-06-18T04:15:58-07:00
by lenscape
This issue arises from a question in the freenode IRC forum: ##imagemagick.

A screenshot taken with KDE ksnapshot produces a png image of 327KB. The following command:

Code: Select all

convert snapin.png -resize 80% snapout.png 
successfully reduces the image dimensions to 80% but increases the file size to 1.1MB.

Gif output, on the other hand, is 204KB.

Why this huge increase in file size for png output and what can I do about it?

Thanks.

Imagemagick 6.3.0

Re: PNG file grows dramatically when image size reduced

Posted: 2007-06-18T12:20:42-07:00
by Bonzo
Somebody I know was having the same problem with from memory the Serif gallery. I think the problem is down to the amount of colours ?

I have just done a test:

Original image
Colors: 44713
Rendering intent: Undefined
Resolution: 72x72
Units: PixelsPerInch
Filesize: 194.854kb

Resized png
Colors: 74088
Rendering intent: Undefined
Resolution: 72x72
Units: PixelsPerInch
Filesize: 384.553kb

Thumbnail png
Colors: 74088
Rendering intent: Undefined
Resolution: 28.34x28.34
Units: PixelsPerCentimeter
Filesize: 377.094kb

Resized gif
Colors: 256
Rendering intent: Undefined
Resolution: 72x72
Units: Undefined
Filesize: 57.8711kb

Thumbnail gif
Colors: 256
Rendering intent: Undefined
Resolution: 72x72
Units: Undefined
Filesize: 57.8711kb


Resized png maximum amount of colours set to 500
Colors: 500
Rendering intent: Undefined
Resolution: 72x72
Units: PixelsPerInch
Filesize: 242.129kb

Re: PNG file grows dramatically when image size reduced

Posted: 2007-06-18T19:39:09-07:00
by anthony
Bonzo, you are quite right that the large increase in the number of colors is the cause. More colors ganerally makes the image harder to compress.

Reducing the number of colors will naturally then help.

However you can probably reduce the resulting size even further by using a ordered dither of the fewer colors. Normal IM color reduction (actually pretty wll all graphic editors) uses a error-correction dither to reduce to arrange the number of colors in a psuedo-random pattern, to simulate the original colors of those areas of the image.

But the psuedo-random pattern itself does not compress well!

ordered dither paterns do compress well! But currently it can not use the 'best' colors found in the image by color quantization, only mathematical colormaps (like you get from -posterization).

It is posible to generate a ordered-dirther using any set of colors. But the algorithm is elusive, any complex. When I figure it out, we may even be able to compress images better than what you are getting!

For examples of using order-dither to reduce the overall size of images, see 'Video to Gif Color Optimization' .

If anyone can help with the above. Please mail me.