Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good SVG renderer for Linux? [closed]

Tags:

linux

svg

I'm developing some scripts to generate SVG files and I wonder what good SVG renderers exist for Linux. I know Firefox/Chrome provide SVG support (and I have the feeling that Chrome is faster at rendering) but maybe there are other standalone SVG renderers that I'm missing. I'm aware of pySVG's existence.

By good enough I mean to cover the SVG 1.1 specification as much as possible. The reason I prefer a standalone library is that my workflow is faster, as I don't have to press F5 every time.

like image 465
rubenafo Avatar asked Jun 25 '12 22:06

rubenafo


2 Answers

Apache Batik is a very good collection of libraries/programs with support for a very large part of the SVG specification. It includes a stand-alone viewer/editor, and a command line rasterizer that can convert SVGs to raster image formats.

like image 137
Sergiu Dumitriu Avatar answered Sep 19 '22 09:09

Sergiu Dumitriu


The SVG 1.1 exported by the draw.io tool is too "modern" for correct rendering by the current Batik, Cairo, qiv, or even FireFox: it seems none of them support the <foreignObject> element. However WebKit does render it properly, so to convert SVG to high-quality images I use the "wkhtmlto..." tools from http://wkhtmltopdf.org.

wkhtmltoimage generates output at screen resolution and its --zoom switch scaled lines and text differently resulting in clipping (although opening the same SVG in Chrome and zooming performed correctly). So instead I'm using wkhtmltopdf to generate an intermediate pdf then rendering that as a high-resolution image with ghostscript:

wkhtmltopdf callbacks.svg callbacks.pdf
gs -sDEVICE=pnggray -sOutputFile=callbacks.png -dBATCH -dNOPAUSE -r900 callbacks.pdf

EDIT: a disadvantage of going via a Page Description Format is that the image file produced may have very large borders. You can experiment with paper sizes and layouts to minimise this or just auto-crop them off, e.g. with ImageMagick:

convert callbacks.png -trim callbacks.png

EDIT: FireFox 49.0.2 (Nov 2016) now renders the draw.io SVG correctly. Haven't retested Cairo or Batik. sample draw.io file

like image 21
Tom Goodfellow Avatar answered Sep 18 '22 09:09

Tom Goodfellow