SVG -> PNG, Massive PLTE chunk difference when scaling

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
abp

SVG -> PNG, Massive PLTE chunk difference when scaling

Post by abp »

Hi All

I have encountered an issue while converting from SVG to PNG and scaling at the same time that I'd like to discuss. In short, the amount of colors used for indexed PNGs (images with PLTE chunk) increase rapidly as I scale down the SVG resource.

I have attached an example of the above. Resource 'smile_100.svg' is the master SVG file. On this master file I do the two below calls producing files 'smile_100.png' & 'smile_73.png'.

convert -filter blackman -alpha on -depth 8 -background none -resize 100.0%!x100.0%! smile.svg smile_100.png
convert -filter blackman -alpha on -depth 8 -background none -resize 73.33%!x73.33%! smile.svg smile_73.png

Things is, that while 'smile_100.png' has 57 indexed colors, 'smile_73.png' has 159! This affects the size of the low res file which in my case is unacceptable.

I have tried almost all possible parameters of '-filter' without any changes. Have also tried blurring, sharpening, etc in the hopes that this might reduce the number of colors. Simply using '-colors n' will mess up the TRNS chunk of indexed PNGs and hence cannot be used.

Can anybody explain to me why the issue I am describing occurs, direct me to some resources on the subject or simply suggest ImageMagick parameters that solves the issue?

Thanks in advance!

smile_100.svg:
Image

smile_100.png:
Image

smile_73.png:
Image

Resources:
smile_100.svg: http://kenneth.io/anders/smile_100.svg
smile_100.png: http://kenneth.io/anders/smile_100.png
smile_73.png: http://kenneth.io/anders/smile_73.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: SVG -> PNG, Massive PLTE chunk difference when scaling

Post by fmw42 »

have you tried adding -colors XX with XX your desired number of colors

see http://www.imagemagick.org/script/comma ... php#colors

also current syntax is typically

convert input options output

also

one % and one ! is sufficient

-resize 100x100%!
abp

Re: SVG -> PNG, Massive PLTE chunk difference when scaling

Post by abp »

have you tried adding -colors XX with XX your desired number of colors
Yes. This was stated in the post: "Simply using '-colors n' will mess up the TRNS chunk of indexed PNGs and hence cannot be used."
one % and one ! is sufficient
Ok. Thanks
abp

Re: SVG -> PNG, Massive PLTE chunk difference when scaling

Post by abp »

Does anybody else have constructive input for this one?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: SVG -> PNG, Massive PLTE chunk difference when scaling

Post by magick »

Resizing an image introduces new colors. Try sampling instead, -sample 73.33%!x73.33%!. The results will not look nearly as nice as the -resize option but it achieves you goal of fewer colors in the output image.
abp

Re: SVG -> PNG, Massive PLTE chunk difference when scaling

Post by abp »

Resizing an image introduces new colors. Try sampling instead, -sample 73.33%!x73.33%!. The results will not look nearly as nice as the -resize option but it achieves you goal of fewer colors in the output image.
The quality of the output when using '-sample' is sadly too poor. Since I am working in very low resolutions, the quality impact of using a point filter is unacceptable. But thanks for your answer anyways, I am sure it will come in handy for me at another time.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG -> PNG, Massive PLTE chunk difference when scaling

Post by anthony »

You could resize the image then use

Code: Select all

     +dither -map original_image 
to remap all colors to the closest matching color in the original image.

No gurantees though.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply