pygobject / pycairo

Python bindings for cairo
https://pycairo.readthedocs.io
Other
622 stars 85 forks source link

Convert animated svg into a png sequence #313

Open qo4on opened 1 year ago

qo4on commented 1 year ago

I didn't manage to convert this animated svg into a png sequence. Is it possible anim

stuaxo commented 1 year ago

Yes, though pycairo is a thing that outputs svgs rather than inputs them. You need a higher level library that can load the SVGs (that may be a library that renders using cairo).

What did you try ?

OT: The SVG itself is quite pleasing / mesmerising to look at.

qo4on commented 1 year ago

I tried this

import rsvg

width = 200
height = 200

svg = rsvg.Handle('anim.svg')
unscaled_width = svg.props.width
unscaled_height = svg.props.height

svg_surface = cairo.SVGSurface(None, width, height)
svg_context = cairo.Context(svg_surface)
svg_context.save()
svg_context.scale(width/unscaled_width, height/unscaled_height)
svg.render_cairo(svg_context)
svg_context.restore()

svg_surface.write_to_png('cool.png')