Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Cropping .svg files on the command line is simple: $ inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose *.svg

I need to do the opposite. I want to fit the drawing into a 64 x 64 points canvas (already set in all .svg files). Unfortunately Inkscape doesn't provide a FitDrawingToCanvas command. Moreover, the fitting should keep the aspect ratio of the drawing.

If it matters: I'm using Ubuntu raring.

share|improve this question
Would resize after fitting the canvas to drawing do the job? See… – Takkat Oct 30 '13 at 19:25
Two questions: (1) the canvas size is already set in each instance, but the drawings are larger than the canvas; or are you inserting an svg drawing into a different svg document?; (2) "keep aspect ratio": this is confusing in light of the 64pt square canvas mentioned in your questions, but do you have a proposed automated decision process for how to handle non-square material? e.g. the height should be 64pt in all cases... – horatio Oct 30 '13 at 20:37
@Takkat: Thanks for the hint. The workflow works, but the aspect ratio gets destroyed. Will look for a solution for that... – Stefan Endrullis Oct 30 '13 at 21:55
@horatio: (1) the drawing in smaller than the canvas and yes, both are in the same file. (2) I want to scale the drawing to the point that max(drawingWidth, drawingHeight) = 64pt. – Stefan Endrullis Oct 30 '13 at 22:00
@Takkat: rsvg-convert has an argument --keep-aspect-ratio :) – Stefan Endrullis Oct 30 '13 at 22:07

You could use viewBox to accomplish what you want. I don't know if there is a way to do this from within Inkscape, but since SVG is a standard format and there may be another tool that will do the job you want. A quick search for "svg command line tools" revealed some interesting results, including this one for creating CSS icons.

A second option would be to write your own tool in your language of choice to do this. The basic gist is to set the viewBox to the height of your document, then set the width and height of the document to want. Finally, set the preserveAspectRatio attribute.

Here's what the modifications described above look like on a document that was originally 744x1052.

   viewBox="0 0 744 1052"
    preserveAspectRatio="xMinYMin slice"
share|improve this answer

I found a way to do this in this question: Inkscape - Center Drawing to Page via Command Line/Terminal

With "foo.svg" as the image to edit:

inkscape --verb=EditSelectAll --verb=AlignHorizontalCenter --verb=AlignVerticalCenter --verb=FileSave --verb=FileQuit foo.svg

To edit all svg images in the current directory:

inkscape --verb=EditSelectAll --verb=AlignHorizontalCenter --verb=AlignVerticalCenter --verb=FileSave --verb=FileClose *.svg

But this second command opens a ton of windows, which will make your computer crash if you're editing too many images. For Linux only, this command will work better:

for img in $(ls *.svg) ; do inkscape --verb=EditSelectAll --verb=AlignHorizontalCenter --verb=AlignVerticalCenter --verb=FileSave --verb=FileQuit $img ; done

For the above command, if any of the files are symlinks, Inkscape will edit the target file that the symlink points to. If you don't want Inkscape to do this, you can filter out any symlinks with this command:

for img in $(ls *.svg) ; do if [[ $(readlink $img) == "" ]] ; then inkscape --verb=EditSelectAll --verb=AlignHorizontalCenter --verb=AlignVerticalCenter --verb=FileSave --verb=FileQuit $img ; fi ; done

While I'm at it, I might as well post the bash script I made for this:

# inkscape-center <file-or-directory>...

_analyse() {
    if [ -d "${1}" ] ; then
        _centerAll "${1}" ;
        _center "${1}" ;

_centerAll() {
    cd "${1}" ;
    for img in $(ls "*.svg") ; do
        _filterSyms "${img}" ;

_filterSyms() {
    if [[ $(readlink "${1}") == "" ]] ; then
        _center "${1}"

_center() {
    inkscape --verb=EditSelectAll --verb=AlignHorizontalCenter --verb=AlignVerticalCenter --verb=FileSave --verb=FileQuit "${1}"

for arg ; do
    _analyse "${arg}" ;

I called it inkscape-center and run it like this:

inkscape-center <file-or-directory>

It takes as many arguments as you want, so you can do something like this:

inkscape-center 1st.svg 2nd.svg 3rd.svg 4th.svg

Be careful- If you specify a directory instead of a file, it'll edit every svg file in that directory.

share|improve this answer
Can you please outline the solution here? – Wrzlprmft May 28 '15 at 6:22
Hi user306916, could you please explain a bit more what we'll find behind the link you provide and why it answers the question? That way, your answer is still of value in case the link breaks at a later time. Link rot is the main reason we really dislike link-only answers here. Thanks for your effort and keep contributing! – Vincent May 28 '15 at 8:37
That makes sense. Done! :) I just copied and pasted the other answer I wrote, which is what that link points to. – GreenRaccoon23 Jun 26 '15 at 6:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.