How to convert a large SVG file to tiled PNG?

I have a large SVG file (about 60 MB, 10000x10000 pixels, but with the potential to get much more), and I want to create, say, a lot of tiled 256x256 PNG images from it (in this example 1600 images, round (10000/256) ^ 2).

Does anyone have an idea on how to do this on a web server (by the way, PHP)? I was thinking about rsvg, but it has no functions to change the bounding box (and I would prefer not to do it manually for each section). ImageMagick can do this, but I'm not very lucky to have it working. Using rsvg to create a large PNG, and then using a tile tool, very large images can work, but I was not lucky to find such a thing! Speed ​​is actually not a problem, although this is desirable, so if the worst comes to the worst, I can study the modification of the SVG bounding box for each section. I could see the generation take forever, though!

Does anyone know of any methods for this?

Edit 2016-03-02:

Recently, I returned to the need to answer this question again, and Inkscape seems to be the only tool that can display SVG for a given area at given sizes ( svgexport almost meets these requirements, but does not allow changing the aspect ratio).

My goal was to stitch SVG into 256x256 fragments, and now I have successfully made a script that can alternate an arbitrarily large SVG, making repeated renderings in inkscape about 16,000 x 16,000 and breaking up the resulting resulting images, I successfully executed SVG, where sizes over 500,000 x 500,000 pixels - no problems with memory usage (it takes a lot of time!)

+6
linux php imagemagick svg
source share
5 answers

inkscape has command line mode for exporting png, using an optional argument to select the export area

 inkscape vector.svg --export-png=raster.png --export-area=0:0:100:100 
+9
source share

I would look at Apache Batik . In particular, their SVG Rasterizer looks exactly what you need.

I have never used it for giant SVG files, so I don’t know if it is optimized for this case or not.

+1
source share

PanoJS seems to be doing what you are asking for. First you need to convert the SVG to a large PNG (for example, using inkscape on the command line) and then use the PanoJS tile to create the tiles. This is a very dangerous beast for memory, but if you can make it work successfully, you can use Javascript PanoJS code to point to your web server. XCD used it for a large image describing money .

0
source share

Check out this question I posted earlier and got the job.

If the image is only 10000x10000, then the script I in the question works best.

If you want to use much larger images, look at the script in my anser.

ImageMagick crop a huge image

0
source share

You might want to edit the original properties of your SVG (copy) to display only certain areas. Use the "width" and "height" properties according to your tile size (256) and "viewBox" in the desired area of ​​the tile (for example, "viewBox =" 512 256 768 512 "for the 3rd tile in the second row). You can do something like this in a loop:

 $sed = "sed 's/width=\"10000\"/width=\"256\"' ".$sourcefile; $sed .= " | sed 's/height=\"10000\"/height=\"256\"'"; $sed .= " | sed 's/viewBox=\"0 0 10000 10000\"/viewBox=\"0 0 256 256\"'"; exec($sed." > ".$tmpfile); exec('rsvg '.$tmpfile.' > '.$tilefile); 

I do not know how this works on very large files.

0
source share

All Articles