Crop SVG from command line

Bug #1722844 reported by fabrice salvaire on 2017-10-11
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Inkscape
Wishlist
Eduard Braun

Bug Description

Some peoples are looking for a command line tools to crop SVG (e.g. for web)

I found this command

inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileQuit foo.svg

But it requires a GUI

--without-gui crashes Inkscape

Would be nice to have an option, to sanitize the SVG, fit the canvas and add an optional margin.

I guess the api is here, it just misses some codes.

johannes (fghgfh832) wrote :

Many, if not all, verbs seem to require GUI. The basic command line interface is a bit restricted and I agree that it would be very useful to have more options, e.g. when one wants to do batch conversion of a large number of images.

But what you want to do, should be possible.

Using command line, you can save as (plain) SVG using
--export-plain-svg=NEWFILENAME

You can fit the canvas of the resulting image by using
--export-area-drawing

BUT this does not work when exporting as SVG. It does work when exporting as EPS or PNG.

So as a workaround, you can export to EPS, then convert back to SVG:

inkscape --without-gui --export-eps=TEMPFILENAME.eps --export-area-drawing OLDFILENAME.svg

inkscape --without-gui --export-plain-svg=NEWFILENAME.svg TEMPFILENAME.eps

More complex operations *might* be possible via Python scripting but I have no experience on that.

Eduard Braun (eduard-braun2) wrote :

I just pushed a fix to master in
https://gitlab.com/inkscape/inkscape/commit/c169d8f366f0765513e08e94057d1e0dc3872c73

It enables the command line switch "--export-area-drawing" when exporting to either plain SVG or Inkscape SVG via command line.

Changed in inkscape:
importance: Undecided → Wishlist
assignee: nobody → Eduard Braun (eduard-braun2)
milestone: none → 0.93
Eduard Braun (eduard-braun2) wrote :
Changed in inkscape:
status: New → Fix Committed
milestone: 0.93 → 0.92.3
Bryce Harrington (bryce) on 2018-05-12
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers