Page 1 of 1

Scaling a PNG image smaller produces a larger file size

Posted: 2007-11-01T11:24:38-07:00
by eldiener
I am using Magick++ as my programming interface, with ImageMagick 6.3.6-4. I scale a PNG image from its current size of 608x308, which has a total file size of 271,465, to a size of 368x169. The resultant PNG image now has a file size of 373,702 !!!

How can this be ?

I can bring both images into PaintShop Pro and the images are both recognized correctly as PNG images and the width and height of the images are correct.

If I open the original image in PaintShop Pro and use its resize feature to scale it down accordingly, the resultant file size is 87,435, which is close to what I expect.

If I try the same sort of scaling from the ImageMagick command line using the convert command, the same increase in file size occurs, so this is not just an issue with my programming interface.

I thought that perhaps some sort of compression algorithm was not occuring but if I try to compress the file from the ImageMagick command line using convert no change in file size occurs.

Hopefully someone will have a clue as to what is happening, but scaling of a PNG image appears somehow incorrect in ImageMagick if scaling the width and height downward produces a much larger file size.

Re: Scaling a PNG image smaller produces a larger file size

Posted: 2007-11-01T12:16:18-07:00
by magick
Its likely you are resizing a colormapped image and it is being promoted to truecolor or your image is 8-bit and its being promoted to 16-bit. Try
  • identify -verbose myimage.png
for your input and output images to determine its properties. To fix, use color reduction to reduce the image back to colormapped, write it as PNG8:, or set the image depth to 8 if it is getting promoted to 16.

Re: Scaling a PNG image smaller produces a larger file size

Posted: 2007-11-02T07:12:47-07:00
by eldiener
magick wrote:Its likely you are resizing a colormapped image and it is being promoted to truecolor or your image is 8-bit and its being promoted to 16-bit. Try
  • identify -verbose myimage.png
for your input and output images to determine its properties. To fix, use color reduction to reduce the image back to colormapped, write it as PNG8:, or set the image depth to 8 if it is getting promoted to 16.
Your second surmise was correct, thank you ! The image is being promoted from an 8-bit image to a 16 bit image. This may be because I have:

#define QuantumDepth 16

set in my magick-config.h file. I am guessing that with the QuantumDepth value, all changes to an image enforce the QuantumDepth, but maybe you would know if that is the case. If so, it is something I must consider, else any other explanation of why the image depth would change would be welcome. But at least I know that the image depth is the reason that the image is getting larger.