Wednesday, July 22, 2015

resizing (scaling) svg images using rsvg-convert

I had some svg files that I wanted to display on a Drupal website, but they were larger than I wanted for the page. For some reason scaling in the html tags wasn't working, so I had to change the source images.



My first thought was to use imagemagick, which I've used for similar tasks in the past, but it does not seem to output svg files very nicely.

Eventually I found a program called rsvg-convert, which worked quite well. I believe it is also possible, perhaps even simple, to resize svg images by directly editing the xml text in the svg file, but I did not have the patience to do read the file specification and figure out how to do that.

I'm on ubuntu, so I installed rsvg-convert with apt-get:
sudo apt-get install librsvg2-bin

I created a directory, copied all of the svg files I wanted to modify into that directory, created a subdirectory for the new files, then created resize.sh in the subdirectory and executed it from there.



resize.sh
for i in `ls .. | grep svg`
do 
    rsvg-convert -f svg ../$i -w 50 -a -o $i
done

reference:
http://ask.metafilter.com/146888/How-to-resize-a-vector-image
(someone here suggests to use rsvg-convert, but doesn't go into any more detail)

No comments:

Post a Comment