If you have a raster image (JPG, PNG, etc.) and want to convert it into a clean, scalable SVG, you can use ImageMagick and Potrace. This method is particularly useful for converting hand-drawn sketches or logos into vector graphics.

Before starting, you need to install ImageMagick and Potrace. These tools work on Linux, macOS, and Windows (via WSL or Cygwin).

Ubuntu/Debian

sudo apt install imagemagick potrace

macOS (Homebrew)

brew install imagemagick potrace

Potrace works with PBM (Portable Bitmap) images, so we first need to convert our image into a black-and-white PBM file using ImageMagick.

convert input.jpg -threshold 50% -monochrome output.pbm
  • -threshold 50% ensures a sharp black-and-white conversion.
  • -monochrome removes grayscale, making it easier for Potrace to trace outlines.

Now that we have a black-and-white PBM image, we use Potrace to trace the bitmap and generate an SVG.

potrace output.pbm -s -o output.svg
  • -s outputs an SVG file.
  • -o output.svg specifies the output file name.

You can open the resulting output.svg in any vector editing software.