Monday, June 8, 2009

Batch convert svg to png

I just opened gnome-terminal and searched:
Code:

$ apt-cache search svg.*png
inkscape - vector-based drawing program
librsvg2-bin - command-line and graphical viewers for SVG files
scribus - Open Source Desktop Page Layout
...


my eye caught librsvg2-bin
Code:

$ apt-cache show librsvg2-bin
...
Description: command-line and graphical viewers for SVG files
The rsvg library is an efficient renderer for Scalable Vector Graphics
(SVG) pictures.
.
This package includes a command-line utility to convert the SVG files
to the PNG format and a graphical SVG viewer.


afterwards, i checked out the package to see the command for it:
Code:

$ sudo apt-get install librsvg2-bin
...

$ dpkg -L librsvg2-bin
...
/usr/bin/rsvg-convert
/usr/bin/rsvg-view
/usr/bin/rsvg
...


Cool, now we know the commands included
Code:

$ rsvg-convert --help
Usage:
rsvg-convert [OPTION...] [FILE...] - SVG Converter
Help Options:
-?, --help Show help options
Application Options:
-d, --dpi-x= pixels per inch [optional; defaults to 90dpi]
-p, --dpi-y= pixels per inch [optional; defaults to 90dpi]
-x, --x-zoom= x zoom factor [optional; defaults to 1.0]
-y, --y-zoom= y zoom factor [optional; defaults to 1.0]
-z, --zoom= zoom factor [optional; defaults to 1.0]
-w, --width= width [optional; defaults to the SVG's width]
-h, --height= height [optional; defaults to the SVG's height]
-f, --format=[png, pdf, ps, svg] save format [optional; defaults to 'png']
-o, --output output filename [optional; defaults to stdout]
-a, --keep-aspect-ratio whether to preserve the aspect ratio [optional; defaults to FALSE]
-v, --version show version information
-b, --base-uri base uri


With some bash scripting you have a script:
Code:

$ cd your-directory-with-the-svgs/
$ for i in *; do rsvg-convert $i -o `echo $i | sed -e 's/svg$/png/'`; done


cheers!

P.S. you can do a similar conversion using inkscape's command line:
Code:

$ cd your-directory-with-the-svgs/
$ for i in *; do inkscape $i --export-png=`echo $i | sed -e 's/svg$/png/'`; done


source: http://ubuntuforums.org/showthread.php?t=820965

No comments:

Blog Archive

About Me

Exclusion of liability Regarding StillStupid: The use you make of the guides, tips and downloads that you listed on this web site or on another website to which I refer is entirely at your own risk. In no way can I be held liable for damage or consequential damages of any kind, which occurs as a result of that use.