When rasterizing an svg file, I would like to be able to set the width and height for the resulting png file. In the following code, only the canvas is set to the required width and height, the actual image content with the original svg file size is displayed in the upper left corner of the canvas (500, 600).
import cairo import rsvg WIDTH, HEIGHT = 500, 600 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) ctx = cairo.Context(surface) svg = rsvg.Handle(file="test.svg") svg.render_cairo(ctx) surface.write_to_png("test.png")
What should I do to make the content of the image the same with the canvas? I tried
svg.set_property('width', 500) svg.set_property('height', 500)
but got
TypeError: property 'width' is not writable
Also, documents for linking python librsvg seem extremely rare, only some random snippets of code on the cairo website.
source share