38

I've been struggling to do something that would seem pretty basic:

In Inkscape, how can I resize the document and its content (i.e. drawings) at the same time?

A little bit of context: I want to resize a fairly large number of SVG documents from The Noun Project (they are typically 100x100px docs) without having to explicitly resize the actual drawings.

N.B: If there's a command line solution, I can work with that too!

8
  • I'm not sure of your end goal, but AFAIK, the document area is somewhat arbitrary aside from printing, where you have an option to only print the document area. However, you can also only print the object area as well, so that may be a way to get around your hurdle.
    – DA01
    Commented Mar 17, 2012 at 18:48
  • @DA01 Well, I think the document's pretty helpful when you export to Bitmap (which is what I'm doing).
    – julien_c
    Commented Mar 17, 2012 at 18:52
  • By the way, is there a way to resize an object that doesn't involve dragging corners, but where you would explicitly specify a size? That might be the thing I'm after :)
    – julien_c
    Commented Mar 17, 2012 at 18:55
  • 1
    even then it's an arbitrary option. You can just as easily draw a containing box as your export 'zone'. In fact, that's how I usually prefer to do it. As for resizing, you can select your objects and then either a) use the status bar on the top and type in your size changes or b) go to OBJECT > TRANSFORM and enter values in the Transform pallet
    – DA01
    Commented Mar 17, 2012 at 22:05
  • @julien_c: I think the point here is that the objects are straight vector art and have no size per se until you output them to a raster device (or file). Their size (inches,pixels, cubits) is, in effect, irrelevant.
    – horatio
    Commented Mar 22, 2012 at 20:48

5 Answers 5

30

You haven't mentioned what OS you're running. I'm using Ubuntu, and I've been able to use librsvg2 successfully.

If you have access to Ubuntu, here's what you can do. First, install librsvg2:

sudo apt-get install librsvg2-bin

Then, cd to the directory that has your SVGs (make sure it only has SVGs!) and use a command like the following:

for old in *; do
    new="$(echo "$old" | sed -e 's/svg$/new.svg/')"
    rsvg-convert "$old" -w 160 -h 160 -f svg -o "$new"
done

This will create a new batch of SVGs with dimensions 200px by 200px, and saved as "original-file-name.new.svg"

Calculating dimensions is somewhat confusing. For converting SVG to SVG, you need to do a little bit of math. The "height" and "width" options in rsvg-convert use pt, not px, in such cases, so use 80 if you want 100px, 120 if you want 150px, and so on.

You can also use rsvg-convert to output PNGs. It is much better at rasterizing the file than ImageMagick, at least in my experience. Notice that you need to change -f to png, you need to change the output save pattern from 's/svg$/new.svg/' to 's/svg$/png/', and you enter the width and height that you want as the pixel values.

for old in *; do
    new="$(echo "$old" | sed -e 's/svg$/png/')"
    rsvg-convert "$old" -w 200 -h 200 -f png -o "$new"
done
7
  • By the way, I'm just assuming that you need to do this in batch mode to a large number of SVGs. If not, you can still use the rsvg-convert as such: rsvg-convert noun_project_1576.svg -w 320 -h 160 -f svg -o noun_project_1576-skewed.svg which will take a source file named "noun_project_1576" and skew it to be 400px by 200px and rename it "noun_project_1576-skewed". Commented Mar 24, 2012 at 15:01
  • @julien_c, just following up: did you try this suggestion and have any luck with it? Commented May 5, 2012 at 18:09
  • Copy and pasted the code in the terminal but return sed: -e expression #1, char 14: unterminted 's' command Missing argument for -o... Any suggestions
    – raphie
    Commented Sep 6, 2014 at 14:21
  • I changed ` to " and now I'm getting Error saving to file: echo svgfile.svg | sed -e 's/svg$/2.svg'
    – raphie
    Commented Sep 6, 2014 at 14:37
  • Great--it'll be even better when librsvg's flowed text bug is fixed...
    – Joce
    Commented Mar 23, 2017 at 9:51
13

There is currently no native way to do that in Inkscape. The only way is to resize content and document separately.

5

While there's a few ways to do it - as noted here - one way that can work really well is to use a viewBox. You simply modify the contents of the SVG tag like so:

<svg
 width="1280"
 height="800"
 viewBox="0 0 1280 800">
    <!-- More markup... --!>
</svg>

What viewBox does is it defines an internal coordinate system for the document. You can then easily scale the document simply by modifying the width and height attributes as necessary.

Note that there are some drawbacks, though. For one thing, there's only certain contexts this works in, specificially if you're somehow directly including the SVG document on your markup page. Using an <img> tag with this may or may not yield unexpected results. You'll have to do some of your own research to figure out how best to do this.

3
  • 2
    This doesn't work for me, and I do not understand why. If I edit the width and height but leave the viewBox as is: When Chrome renders the raw svg file, it shows only a small portion of the content. When Inkscape renders it, it shows the entire content, but its much bigger than the page, which is the same small (top left) portion which Chrome showed. So, altogether: the content is not scaling according to viewbox coordinates. My SVG has several child svg elements in it, but they are all transformed based on (I assume) the viewbox coordinates.
    – CPBL
    Commented Apr 15, 2015 at 19:55
  • Worked for me in Inkscape 0.92.3, Firefox 66, and Chromium 73.
    – Socowi
    Commented Apr 3, 2019 at 21:28
  • @CPBL I don't know anything about the SVG format, but I would assume the viewbox is literally just that: the box through which the content is viewed. If you make it smaller than the content, the content will be cut off (except in Inkscape, you'll see content even if it's outside the page). What were you expecting to happen?
    – Clonkex
    Commented Jun 25, 2020 at 3:07
3

What I did was to first changing both width and height by multiplying them by 10 from Document Properties,

Document Properties

Then going to Edit > XML Editor and then adding transform scale(10, 10) to the root element,

XML Editor

Then pressing for example on Path > Union to make Inkscape actually apply the specific transform on the path.

Guess this isn't the way it supposed to work but I just wanted to help myself the next I needed this as I did it once before and forgot for a moment and that's why I posted it here which hopefully would be useful to other also :)

1

I was looking for a way to do this and im used to using notepad++ for not exactly similar things but sorta seemed that way, using normal find/replace i could change "in files" or open them all if not thousands and find your height and width, which for me was 100px but the viewbox was a little more annoying as the icons from thenounproject had different values, doing a find replace using regex expressions firstly for the normal numbers.

Find What: viewBox=\"[\d ]*\" Replace With viewBox="0 0 512 512" (or whatever you want the numbers to be).

Then there was some even more annoying ones that had decimal points, like 96.987 (tossers) so

Find What: viewBox=\"[\d. ]*\" Replace With: viewBox="0 0 512 512" (or whatever you want the numbers to be)

Probably not a traditional way to change image properties but SVG are XML files essentially as im aware, this took about 5 minutes to search about replacing strings inside quotes and 5 minutes to do in notepad++. Hope it maybe helps someone.

Recommend taking a backup of your files before you do any of the above as there is no easy way to undo if you muff it up (or at all, if your changing "in files").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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