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:
smile_100.png:
smile_73.png:
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
SVG -> PNG, Massive PLTE chunk difference when scaling
- 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
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%!
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
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."have you tried adding -colors XX with XX your desired number of colors
Ok. Thanksone % and one ! is sufficient
Re: SVG -> PNG, Massive PLTE chunk difference when scaling
Does anybody else have constructive input for this one?
Re: SVG -> PNG, Massive PLTE chunk difference when scaling
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
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.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.
- 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
You could resize the image then use to remap all colors to the closest matching color in the original image.
No gurantees though.
Code: Select all
+dither -map original_image
No gurantees though.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/