Convert SVG with Inkscape/Bash

Command line tips for the lazy.

I'm not sure if lazy is the right word if one spends a full day in finding out how to automate a small repetitive task that would have cost you half an hour, and you might never need again. Maybe I should rephrase. 'Command line tips for the crazy'. Anyway, this is a mini post for those of you who are not very familiar with bash and the command line, but need to convert lots of svg files to png or psd. (these insctructions are for linux, but should apply to windows too somehow)

Copy and paste the following bash snippet in a text document and name it whatever-you-like.sh (for example).

#!/bin/bash
for var in "$@"
do
	s=${var##*/}
	base=${s%.svg}
	echo 'converting' $var
	inkscape -f $var -e $base.pdf
	echo 'done!'
	echo '*****'
done

Right click the text document and make it executable (or 'chmod a+x whatever-you-like.sh' at the command line, since we're talking about that anyway). It's very handy to make an alias for this sort of custom bash scripts so you wouldn't have to type path and file name every time you need them, but I'm not going into that now. Then cd to your image folder and type

whatever-you-like.sh *.svg

This will convert all svg files in that folder to pdf files with the same name. You can change the script and output to png, ps and eps and it will convert accordingly. Note that you have to either make an alias in your .bash_aliases to call the scripts, or explicitly mention the full path to it in the command like so /path/to/scripts/whatever-you-like.sh *.svg

All info on inkscape command line here: http://inkscape.org/doc/inkscape-man.html

Comments

This is perfect!

I'm looking this option to PDF like a option to print as CMYK. This is possible?
I'm working on real paper print, off-set on Brazil, and it's maybe a solution. But inkscape don't work with CMYK directly.
Has a anyway to convert a PDF but with CMYK option? Or another path to do this?
i dont know solution to change the properity software to Free Software, when the subject is Corel World to Inkscape world.

Thanks from Brazil.

Hello Adriano, there is no

Hello Adriano, there is no way I know of to do such a thing directly, since Inkscape is not a print oriented application. But the exported PDF has an alpha channel, and in Photoshop or Gimp you can make a selection from this alpha channel, and fill it with any color you want (like pure Y, M, C or K). So it doesn't matter what color you export the drawing from Inkscape, you have to edit it for printing anyway. Hope you get it working,

greetings from Berlin!
Bruno

Very helpfull

Thank you,
very helpful for me, I use it to export my drawing for my master degree mémoire in latex. I want both pdf and eps for the different compilers, (almost) all my figures are in svg and sometimes I edit them.
Here is my script wich autamatically put my figures in the right folder:

code:

for var in ./illustrations_svg/*.svg

do

s=${var##*/}

base=${s%.svg}

echo 'converting' $var

inkscape -D $var -A ../memoire/illustrations/$base.pdf;
echo $base'.pdf created'

inkscape -D $var -E ../memoire/illustrations/$base.eps;
echo $base'.eps created'

echo 'done!'

echo '*****'

done

png to svg ?

Hi,

it's there an possible for converting png's into svg without any asking ? because with :

for f in *.png ;do inkscape -f $f -l $themehomefolder/scalable/$workingfolder/${f%.png}.svg ; done

become i ever an ask, but i need it full as batch without any other programms.. can you help me ?

best regards
Blacky
p.s.: can you mail me if you have an better option ?

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.