Can convert produce static PNGs from an animated SVG?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
FrereTuck
Posts: 22
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Can convert produce static PNGs from an animated SVG?

Post by FrereTuck » 2019-11-08T12:43:13-07:00

Hi there,

I generated a few animated SVG thanks to termtosvg.
My ultimate goal is to produce image files or videos light enough to fit in a web page... because animated SVG are not handled correctly by the blog software I use.
So, I switched to GIF thanks to asciinema, but these GIF files are just huge, and they sometimes just don't generate because of bugs or memory limitation.
For the time being, that is a total mess.
So... I'd like to start back from the SVG and try to generate PNG files, or one APNG file, and then feed that to ffmpeg to get an MP4 file.

My first tries with the convert tool give me the very first "frame", and that's all.
Is there anything I can do to get several PNG from the animated SVG, or an APNG?

Thanks a bunch.

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can convert produce static PNGs from an animated SVG?

Post by fmw42 » 2019-11-08T12:48:50-07:00

ImageMagick does not support APNG as far as I know. I have no experience with animated SVG. I suggest you use Inkscape to render it. Perhaps Inkscape (which ImageMagick can use) might be able to handle the animated format.

Which SVG renderer are you using with ImageMagick? It can be the ImageMagick internal MSVG/XML (not very good), RSVG (better) or Inkscape (best)?

FrereTuck
Posts: 22
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: Can convert produce static PNGs from an animated SVG?

Post by FrereTuck » 2019-11-08T12:52:33-07:00

Thanks Fred.
I don't know which one I'm using, but I know it's not Inkscape's.

Code: Select all

convert -list format|grep -i svg
     MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
      SVG  SVG       rw+   Scalable Vector Graphics (XML 2.9.4)
     SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (XML 2.9.4)
I guess I should install Inkscape for ImageMagick (as Inkscape is already installed in standalone), and then, automagically, I will be able to use it with ImageMagick?

snibgo
Posts: 12301
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can convert produce static PNGs from an animated SVG?

Post by snibgo » 2019-11-08T14:07:21-07:00

Interesting. Downloading the examples page https://nbedos.github.io/termtosvg/pages/examples.html and associated files, and loading htop_gjm8.svg into standalone Inkscape, Inkscape reports errors and warnings, then renders the entire animation as a single tall image. But Firefox v70.0.1 seems to show the animation correctly.

This suggests that rendering the animated SVG with standalone Inkscape, and chopping the result into PNG frames, and feeding those to ffmpeg, might work.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can convert produce static PNGs from an animated SVG?

Post by fmw42 » 2019-11-08T16:58:08-07:00

XML 2.9.4 means the internal MSVG/XML renderer of ImageMagick, which is the least functional. You could do as snibgo suggests or perhaps try rsvp_convert from RSVG. If that works, then you could install RSVG as a delegate to ImageMagick.

FrereTuck
Posts: 22
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: Can convert produce static PNGs from an animated SVG?

Post by FrereTuck » 2019-11-12T02:50:13-07:00

It looks like rsvg-convert is struggling with the produced SVG:

Code: Select all

rsvg-convert aom.cast.svg >aom.cast.svg.png

(rsvg-convert:12387): librsvg-WARNING **: 10:44:22.506: CSS parsing error


(rsvg-convert:12387): librsvg-WARNING **: 10:44:22.506: CSS parsing error


(rsvg-convert:12387): librsvg-WARNING **: 10:44:22.506: CSS unrecoverable error

parsing error: 12:12:could not recognize next production
parsing error: 13:17:while parsing rulset: current char must be a '}'
parsing error: 13:16:while parsing declaration: next property is malformed
Only the first "frame" is generated.
As for Inkscape, I have the same behaviour as snibgo, I get a very tall image. That's interesting.
I should maybe try to find an animated SVG "cleaner" before giving it as an entry to any other tool.

Thanks.

Post Reply