How to crop SVG?
How do you crop all empty space from an SVG file, specifically from the command line?
I have several SVG files formatted to the standard A2 letter document size, and I need to bulk crop them down so their view box is the same as the minimum bounding box for their contents.
I can do this in Inkscape using the "Resize Page to Selection" option, but I don't see any way to access this function from the command-line.
2 Answers
Try:
inkscape --batch-process \ --verb "EditSelectAll;FitCanvasToSelection;FileSave;FileQuit" \ filename.svgUnder Mac OS the following command line worked:
inkscape -g --verb="FitCanvasToDrawing;FileSave;FileQuit" filename.svgNote that if I provide three different --verb option (which is recommended by the other answers), it didn't work (probably, only the last verb was executed).
It looks like the "Resize Page to Selection" option is available via command line! Check it out here:
inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileQuit *.svg(Use FileClose for older versions of Inkscape.)