Skip to content
Advertisement

How to convert large SVG file to tiled PNGs?

I have a large SVG file (approx. 60 MB, 10000×10000 pixels but with the potential to get much larger), and I’m wanting to create, say, many tiled 256×256 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 256×256 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!)

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement