Page 1 of 1

resize a png, but the size get bigger

Posted: 2019-02-02T20:58:38-07:00
by tczf1128
I resize a png from 750x981 to 499x653, but the size get bigger. why?

http://test-1257746263.picsh.myqcloud.c ... bg02_1.png

Code: Select all

convert static_web_bg02_1.png -resize 499x653 xx.png
I find the type changed, from PaletteAlpha to TrueColorAlpha.

Re: resize a png, but the size get bigger

Posted: 2019-02-02T22:09:13-07:00
by snibgo
Resizing calculates each output pixel from a number of input pixels. Therefore it usually increases the number of unique colours:

Code: Select all

magick static_web_bg02_1.png -unique-colors info:
static_web_bg02_1.png PNG 231x1 231x1+0+0 8-bit sRGB 0.031u 0:00.031

magick static_web_bg02_1.png -resize 499x653 -unique-colors info:
static_web_bg02_1.png PNG 320713x1 320713x1+0+0 8-bit sRGB 0.219u 0:00.218
The number of colours has increased from 231 to 320713, so the image can no longer be stored as a palette type.

You can use "-sample" instead of "-resize", or use "-colors 255" after "-resize".

Re: resize a png, but the size get bigger

Posted: 2019-02-02T22:50:07-07:00
by tczf1128
what is the api in c about -colors options?

Re: resize a png, but the size get bigger

Posted: 2019-02-02T23:00:59-07:00
by snibgo
I think it is QuantizeImage() in quantize.c.