Command line Scripts to Convert SVG files to EPS, PDF and PNG

Theses shell scripts require the impressive inkscape editor.

svg2png

This first script creates a PNG file with correct alpha (a.k.a opacity) values.

#!/bin/zsh

print_usage (){
echo “USAGE:”
echo -e “\t $0 inputfile.svg [outputfile.png]”
}

build_png_filename(){
echo “$1″ | sed -e ‘s@.svg@.png@g’
}

if [ “$1″ = “” ]
then
print_usage
exit
fi

if [ “$2″ = “” ]
then
OUTPUT=`build_png_filename $1`
else
OUTPUT=$2
fi

echo “Converting $1 to $OUTPUT …”

inkscape -z -T -e $OUTPUT $1

svg2eps

Since the PS and EPS format do not handle opacity, the alpha values of the SVG files will be removed. If you really need alpha values, use the raster conversion (e.g. to PNG).

#!/bin/zsh

print_usage (){
echo “USAGE:”
echo -e “\t $0 inputfile.svg [outputfile.eps]”
}

build_eps_filename(){
echo “$1″ | sed -e ‘s@.svg@.eps@g’
}

if [ “$1″ = “” ]
then
print_usage
exit
fi

if [ “$2″ = “” ]
then
OUTPUT=`build_eps_filename $1`
else
OUTPUT=$2
fi

echo “Converting $1 to $OUTPUT …”

inkscape -z -T -E $OUTPUT $1

svg2pdf

  • Alpha values: ok
  • Gradient: depends on your PDF viewer

#!/bin/zsh

print_usage (){
echo “USAGE:”
echo -e “\t $0 inputfile.svg [outputfile.pdf]”
}

build_pdf_filename(){
echo “$1″ | sed -e ‘s@.svg@.pdf@g’
}

if [ “$1″ = “” ]
then
print_usage
exit
fi

if [ “$2″ = “” ]
then
OUTPUT=`build_pdf_filename $1`
else
OUTPUT=$2
fi

echo “Converting $1 to PDF…”

inkscape -z -T -A $OUTPUT $1

About these ads

4 Responses to Command line Scripts to Convert SVG files to EPS, PDF and PNG

  1. pavel says:

    rsvg-convert convertor does not need inkscape and uses the same library. (to be found in gnome-base/librsvg)

  2. dav says:

    Correct : package librsvg-bin on Ubuntu
    Thanks ;)

  3. anon says:

    Useless. That does not convert anything, that just calls inkscape. Lame.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: