Convert Raster Graphics to Vector Graphics

Have you ever wanted to convert a raster image (.jpg, .png, etc.) to a vector image (.svg)? Maybe not yet, but in my post on Installing Songbird, when we added Songbird to the menu, we did not have an icon to set for the menu item. It turns out that this is because we need a .svg image and the Songbird tarball only came with a .png image. No worries, though, we'll go through converting raster to vector and, specifically, how to convert the songbird.png image to a vector image for use on our menu.

In order to do this, we're going to make use of two programs: ImageMagick and Inkscape. ImageMagick is a powerful command line utility for all kinds of graphics manipulations. Inkscape is more widely known as an open source GUI vector graphics editor; however, it also comes with its own set of command line tools. Let's make sure we have these two programs installed:

# apt-get update
# apt-get install imagemagick inkscape

While it is possible to do this though the Inkscape GUI, I find the whole process easier and faster right from the command line. We will use ImageMagick to resize images, if necessary (refer to my first ImageMagick post if you have questions about resizing images with ImageMagick), and we will use Inkscape to do the actual conversion. The command to do the actual conversion is actually very simple:

$ inkscape InputImage.png --export-plain-svg=OutputImage.svg

When you run this command, expect to see a message similar to the following:

(inkscape:30498): GLib-GObject-CRITICAL **: g_object_set_qdata_full: assertion `quark > 0' failed

This is OK, your image still got converted. Now, let's use this to get the songbird.png image in place for use on our menu. Let's start by copying the songbird.png image into out home directory to make things easier:

$ cp /usr/share/Songbird/songbird.png ~/

Now we can use the mogrify command to resize this to a 48x48 pixel image and then use the inkscape command to convert this to songbird.svg:

$ mogrify -resize 48x48 songbird.png
$ inkscape songbird.png --export-plain-svg=songbird.svg

Now, we'll just copy our new songbird.svg image into the same directory as all the other menu icons:

# cp songbird.svg /usr/share/icons/hicolor/scalable/apps/

If we set up Songbird in your menu the way I described before, then all we will need to do is to restart X (Ctrl + Alt + Backspace) and our new songbird.svg image should should show up in our menu.

See you next time

No comments:

Post a Comment