Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

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
1  
Would resize after fitting the canvas to drawing do the job? See graphicdesign.stackexchange.com/questions/6574/… –  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

2 Answers 2

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.

<svg
   width="64"
   height="64"
   viewBox="0 0 744 1052"
    preserveAspectRatio="xMinYMin slice"
share|improve this answer

Your Answer

 
discard

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.