How to convert an svg file to png with fixed pixel size/resolution

I did find the solution myself :slight_smile:

new_height = 48
r = Rsvg.handle_new_from_file(filename_in)
d = Rsvg.handle_get_dimensions(r)
scalingfactor = new_height / d.height
cs = Cairo.CairoImageSurface(round(Int,d.width * scalingfactor), new_height, Cairo.FORMAT_ARGB32)
c = Cairo.CairoContext(cs)
Cairo.scale(c, scalingfactor, scalingfactor)
Rsvg.handle_render_cairo(c,r)
Cairo.write_to_png(cs,filename_out)

Edit: I was inspired by the rsvg manual

2 Likes