Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert large SVG file to tiled PNGs?

I have a large SVG file (approx. 60 MB, 10000x10000 pixels but with the potential to get much larger), and I'm wanting to create, say, many tiled 256x256 PNG images from it (in that example there would be 1600 images; round(10000/256)^2).

Does anyone have any idea of how to do this on a web server (running PHP amongst other things)? I thought about rsvg, but it doesn't seem to have any functionality to modify the bounding box (and I'd rather avoid doing it manually for each section). ImageMagick might be able to do it, but I've not been having much luck with getting it to work. Using rsvg to create a large PNG and then using a tool dedicated to tiling very large images might work, but I've not had any luck finding such a thing! Speed isn't really an issue, although it is desirable, so if the worst comes to the worst, I might look into modifying the SVG's bounding box per section. I could see the generation taking forever, though!

Anyone know of any methods to do this?

Edit 2016-03-02:

I recently came back to needing an answer for this question again, and Inkscape appears to be the only tool which can render SVGs for a given area at given sizes (svgexport almost meets these requirements, but it doesn't let you change the aspect ratio).

My aim was to tile an SVG into 256x256 tiles, and I've now successfully made a script which can tile an arbitrarily large SVG by doing repeated renderings in inkscape of about 16,000 x 16,000 and tiling the resulting images. I've successfully rendered SVGs where the dimensions are over 500,000 x 500,000 pixels—no problems with memory usage (it just takes a long time!)

like image 596
Robert Avatar asked Jun 25 '10 22:06

Robert


People also ask

Are SVGs larger than PNGs?

SVGs are far smaller in size than PNGs and aren't likely to slow down your computer or website. (However, very detailed designs may slow down an SVG.) Because they're a vector file format, you can scale SVGs up or down without any loss in quality.


2 Answers

inkscape has a command line mode to export pngs, taking an optional argument to choose which area to export

inkscape vector.svg --export-png=raster.png --export-area=0:0:100:100
like image 195
second Avatar answered Sep 28 '22 01:09

second


I'd look at Apache Batik. In particular, their SVG Rasterizer looks like just what you need.

I've never used it for giant SVG files, though, so I don't know if it's optimized for that case or not.

like image 20
Ken Avatar answered Sep 28 '22 01:09

Ken