How to set the background color when rendering a PNG using PythonMagick How to set the background color when rendering a PNG using PythonMagick python python

How to set the background color when rendering a PNG using PythonMagick


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.


I don't see the problem if it works with command then use this:

image = 'convert -background red access.svg access.png'os.system(image)

And don't forget to import os

import os

additional you can use vars inside the command (don't forget to rename the vars):

image = 'convert -background '+background+' '+file_from+' '+file_to


This might be a circuitous way of getting to the solution, but could you create a separate background image in the colour you want and then compose the images together?

I think it would look something like this:

image.composite(background, 0, 0, PythonMagick.CompositeOperator.SrcOverDst)

I have very little experience with PythonMagick, but that is what I would have tried after failing to set the background.

Sources: