I have a SVG image here which is generated with 'empty space', i.e. only in the top-left corner is image content, whereas the rest is blank. I think it should be trivially possible to have an automated way to crop the image size to the bounding box of the objects - at least for some svg tooling like rsvg. However I am unable to find the 'command line trick' for this, etc.
I would like to do this on the command line (i.e. as part of a build script)
In principle I would be interested in a solution to the same problem but for pixel-based formats such as PNG as well.
rsvg does not have command line utilities for this problem, but Inkscape in its non-GUI mode has:
will crop the file to the bounding box of all objects of the document. See the man page for a full documentation of the inkscape command line options. Especially note the
--shell
mode for batch processing multiple images.For pixel-based formats there is the imagemagick
-trim
option: