Unix & Linux Asked by Village on December 10, 2020
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?
Here is a wiki comparsion of all Bitmap-to-SVG tools. I recommend two tools based on my own testing. Both of them can convert bitmaps to SVGs in a batch manner.
imagetracerjs is a free js/java tool, which can vertorize the bitmaps while keeping colors.
vectormagic is a commercial tool and it outperforms other tools in my testing.
Answered by Lei Yang on December 10, 2020
potrace
is the tool for that. You can process them bulk, but first you have to convert the images to monochrome:
ls ./*.jpg | xargs -L1 -I {} convert -monochrome {} {}.ppm
ls -1 ./*.ppm | xargs -L1 -I {} potrace {} -r 300 -b svg -o {}.svg
Install on Ubuntu:
sudo apt install potrace
If you want to convert images that are not monochrome, Inkscape
has a tracer tool base on potrace that support multiple colors, it first converts the image to color layers and then it trace those and combines the result.
To use the tracer, load or import an image, select it, and select the Path > Trace Bitmap item, or Shift+Alt+B.
See
Answered by Eduard Florinescu on December 10, 2020
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:
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:
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.
Answered by terdon on December 10, 2020
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:
Here is the resulting image:
Answered by rking on December 10, 2020
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
Looking at the potrace
website you can apparently go directly from BMP to SVG.
$ potrace -s input.bmp -o output.svg
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.
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.
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
Answered by slm on December 10, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP