1

I've made 144 different PNG images. Now I want to convert (trace) them to SVG. What's the best free tool to make this?

IMPORTANT: The images consist of only black and transparent parts. Their sizes are 600 * 600 pixels. They aren't so complicated. Example:

enter image description here

P.S. I'm using Ubuntu 20 (operational system, a version of Linux). Maybe there's some good software for it?

3
  • 1
    Get Inkscape. With it you can make easily tracing parameter tweaks if needed and be sure the ransparency occurs also in the result. No guarantee it's the best, so this cannot be an answer. Naming the best needs knowing them all and knowing also what limitations you have. Ubuntu closes off Windows tools. Online bitmap tracers can demand some rights (for ex. insert to their gallery or you cannot sell it without paying to the site) and you may have no right to upload some stuff.
    – user287001
    Dec 6, 2020 at 16:52
  • I am sure Inkscape is good, I even have it on my device, but, unfortunately, I have too many files to do it - opening it 144 times.
    – Yanb
    Dec 6, 2020 at 16:56
  • See graphicdesign.stackexchange.com/questions/26275/… - you can also do that with autotrace: graphicdesign.stackexchange.com/questions/60107/… (just don't use -centerline option).
    – Takkat
    Dec 6, 2020 at 19:29

2 Answers 2

6

Thanks, @Billy Kerr!

I saw the posts on StackOverflow (first and second) and figured out I'll need to use potrace.

First, convert PNG files to BMP, because potrace can work only with BMP. It is possible to do using an online site, but it's easier and always free offline.

To process multiple files using potrace, a bash script is needed:

#!/bin/bash

for filename in ./*.bmp; do
    for ((i=0; i<=3; i++)); do
        potrace --svg $filename
    done
done

The script iterates through all the elements of the current directory and converts them all to SVG using potrace.

But to use it in the terminal, first make it executable by writing

chmod +x [your filename].sh 

and then run it:

./[your filename].sh

After that, the terminal will work a bit, so don't worry, the images are processing - approximately half of a second per image.

4
  • Excellent!, but I take it you also had to convert the PNGs to BMP first. If so you should maybe mention that too.
    – Billy Kerr
    Dec 7, 2020 at 11:48
  • Yes, thanks, I've forgot it
    – Yanb
    Dec 7, 2020 at 13:51
  • 1
    Note for those following along at home, potrace is embedded into Inkscape, as of 2014-2021. Above is good for command-line batching, but for handling a small number of files, Inkscape with its GUI is the cat's pajamas. May 8, 2021 at 1:57
  • Instead of simply saying "First, convert PNG files to BMP", it might be nice if the script actually showed how to do that, e.g. with ImageMagick's convert. If I had more time, I'd test and submit an edit... alas, I need to run, so hoping a comment is helpful.
    – lindes
    May 19 at 22:49
4

You can't actually "convert" PNGs to SVG. It's not possible. There's no one to one mapping of raster images directly to vector images.

However, you can certainly auto trace raster images to make vectors, but results may vary and depend a lot on the kind of image, and the quality of the original, and the settings used in vector software. Inkscape which is free and Open Source has a Trace Bitmap feature.

For more high quality SVGs, or when a raster image is not good enough quality to auto trace, these often need to be hand crafted. Probably not what you want to hear, however the example image you posted looks good enough.

It may be possible to run Inkscape using the command line for a batch of images. Unfortunately I can't really help you there, but it's something you might want to research.

4
  • Thanks, I'll try and search for something more or less automatic.
    – Yanb
    Dec 6, 2020 at 17:06
  • Extensions for Inkscape are written in Python, aren't they? Would that imply that the automation of the tracing could be done with a Python script?
    – fred_dot_u
    Dec 6, 2020 at 17:11
  • @fred_dot_u I think you could be right, but I'm no programmer, so can't say for certain.
    – Billy Kerr
    Dec 6, 2020 at 17:14
  • @Yanb - maybe check out this related post over on stack overflow: stackoverflow.com/questions/1132601/…
    – Billy Kerr
    Dec 6, 2020 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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