Page 1 of 1

SVG -> PNG, Massive PLTE chunk difference when scaling

Posted: 2009-08-27T06:32:36-07:00
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

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

Posted: 2009-08-27T08:03:17-07:00
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%!

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

Posted: 2009-08-27T08:24:35-07:00
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

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

Posted: 2009-09-01T06:08:10-07:00
by abp
Does anybody else have constructive input for this one?

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

Posted: 2009-09-01T06:12:55-07:00
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.

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

Posted: 2009-09-01T07:33:00-07:00
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.

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

Posted: 2009-09-01T21:11:30-07:00
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.