resize a png, but the size get bigger

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
tczf1128
Posts: 28
Joined: 2018-12-04T22:47:49-07:00
Authentication code: 1152

resize a png, but the size get bigger

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize a png, but the size get bigger

Post 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".
snibgo's IM pages: im.snibgo.com
tczf1128
Posts: 28
Joined: 2018-12-04T22:47:49-07:00
Authentication code: 1152

Re: resize a png, but the size get bigger

Post by tczf1128 »

what is the api in c about -colors options?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize a png, but the size get bigger

Post by snibgo »

I think it is QuantizeImage() in quantize.c.
snibgo's IM pages: im.snibgo.com
Post Reply