Inkscape - cropping SVG files on the Command Line
A little post as an aide-mémoire.
I've found a lovely set of SVG playing cards. The only problem is each image is displayed within a page. This means the relatively small cards have an enormous white margin.
Within Inkscape (the vector image editor for Linux) it's possible to crop the margins by going to:
File > Document Properties > Resize Page To Content > Resize page to Drawing or Selection
That's a pain in the arse for adjusting 52 images. Luckily, Inkscape will take command line arguments (called verbs). This means we can point it to all SVG files in a directory, instruct it to Fit to Drawing, and save the file again.
It all takes place on one line.
inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose *.svg
Run that, the Inkscape window will pop up for each file, and automatically close once saved. I'm not sure if there's a way to do it on a headless install.
Sean says:
Ralph says:
Terence Eden says:
musikai says:
Victor says: