I'm trying to render an SVG->PNG using PythonMagick, but it seems that the background color is ignored.
Using the ImageMagick command, things work as expected:
tmp$ convert -background none access.svg access.png
tmp$ convert -background red access.svg access2.png
which results in transparent and red backgrounds respectively.
But using PythonMagick, it seems the background color is ignored:
import PythonMagick
svg = PythonMagick.Image('access.svg')
svg.backgroundColor().to_std_string()
'#FFFFFFFFFFFF'
svg.backgroundColor().alpha()
0.0
svg.backgroundColor('none')
svg.backgroundColor().to_std_string()
'#0000000000000000'
svg.backgroundColor().alpha()
1.0
svg.write('access.png')
svg.backgroundColor('red')
svg.backgroundColor().to_std_string()
'#FFFF00000000'
svg.backgroundColor().alpha()
0.0
svg.write('access2.png')
Checking the output shows that both pngs have a white background. Is there another way to set the background color so that it is recognised when writing the image?
Upload your PNG file by clicking the “Choose File” button. Under “Tools”, choose “Painting Tools” > “Brush” and select the color that you want for your PNG file. Next, brush the background of your PNG file with the mouse pointer. Lastly, save your file by clicking the “Download” button.
How to save a PNG with a white background. This is simple – just save the PNG as a JPG and your JPG will automatically have a white background. That's because when you save a PNG with a transparent background as a JPG, Photoshop automatically replaces the transparent parts of the image with white. That's it for now.
ImageMagick (and PythonMagick as its python API) has very poor SVG support. Do not even expect that it will render SVG file as it is written in the SVG specification. It converts SVG into internal MVG language and then converts to PNG. See http://www.imagemagick.org/script/magick-vector-graphics.php
ImageMagick is not a tool for manipulating vector graphics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With