Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have many gray scale bitmaps that I need to convert to a vector format, such as SVG. I have been using Inkscape, which gives nice results, but this takes about 10-15 minutes to open, convert, and save a file. Is there a batch or command line tool that can convert these?

share|improve this question
    
you may want to have a look at potrace as well. –  Stéphane Chazelas Jan 25 at 0:49
    
it is also possible to use inkscape as batchtool link –  bersch Jan 25 at 1:20
add comment

3 Answers 3

potrace

I found this example on SO in a Q&A titled: How to convert a JPEG image into SVG format using ImageMagick?. One of the answers suggested potrace.

$ convert input.jpg output.ppm
$ potrace -s output.ppm -o svgout.svg

Results

           ss #1             ss #2

Looking at the potrace website you can apparently go directly from BMP to SVG.

$ potrace -s input.bmp -o output.svg

autotrace

Another option to potrace is autotrace.

$ autotrace -output-file ouput.svg -output-format svg --color-count 4 input.bmp

You'll likely have to play with the --color-count to get an image that suites your needs.

Results

                                                 ss #3

Which to use?

Of these 2 it really depends on the source material. If you're converting images then potrace is likely the better option. For non-photo material such as fonts and inanimate objects such as scenery that includes things like roads, then autotrace with its --centerline switch.

While not optimal for photos, it does good job on line art and poster-like images. Doesn't do too well with color. Autotrace has some features not available in the embedded Potrace dialog in Inkscape. For example, there is a centerline switch that is especially usefull for tracing roads (in maps) or font characters.

Batch conversions

You can wrap either of these commands in a for loop in Bash, which will make easy work of doing bulk conversion tasks.

$ for i in *.bmp; do <CONVERSION TOOL> ... "$i"; done

References

share|improve this answer
add comment

Autotrace

You could try autotrace.

Using the following command you get the following results:

autotrace --output-format svg --output-file output.svg --color-count 4 imgsrc.jpg

I had to take a screencapture of the resulting svg and save as png to show the output.

Here is a source image jpg:

skull source

Here is the resulting image:

skull convert

share|improve this answer
add comment

Normally, I do all my image manipulation tasks with convert from ImageMagic but I can't get it to play nice with svg files. You can, however, use inkscape itself from the command line:

for i in *bmp; do inkscape -f "$i" -l "$i.svg"; done

That will create files called foo.bmp.svg. To get the names right, try this:

for i in *bmp; do inkscape -f "$i" -l "${i%.bmp}.svg"; done

The problem with this approach is that, at least on my system, it pops up an annoying graphical dialog asking if I want to link or embed the image:

                                 enter image description here

So, you still need to click OK manually, but it is still much much faster than doing it file by file.

The output images are identical as far as I can tell:

   enter image description here


Theoretically, both convert and rsvg-convert should be able to do this but I couldn't get it to work well on my images in the few minutes I spent trying. They're both worth looking into nevertheless.

share|improve this answer
    
I'm not positive but on the Inkscape website it says that it now has potrace embedded, so I wonder if it's just using that tool anyway? quote: "Potrace is now embedded into Inkscape. You don't need to run it separately." -- wiki.inkscape.org/wiki/index.php/Tools –  slm Jan 25 at 2:12
    
I suspect Inkscape will simply embed the bitmap image inside the SVG, hence their identical look. –  user2428118 Jan 25 at 6:51
    
@user2428118 I suspect you're right. That may or not be a problem depending on what exactly you want to do with these images. –  terdon Jan 25 at 17:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.