Crop SVG from command line

Bug #1722844 reported by fabrice salvaire
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Fix Released
Patrick Storz

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.

Revision history for this message
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

You can fit the canvas of the resulting image by using

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.

Revision history for this message
Patrick Storz (ede123) wrote :

I just pushed a fix to master in

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
Revision history for this message
Patrick Storz (ede123) wrote :
Changed in inkscape:
status: New → Fix Committed
milestone: 0.93 → 0.92.3
Bryce Harrington (bryce)
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers