Potrace is a CLI tool for tracing a bitmap, transforming a bitmap into a smooth, scalable image (SVG). The input needs to be a bitmap (PBM, PGM, PPM, or BMP format), and the output is one of several vector file formats. A typical use is to create SVG or PDF files from scanned data, such as company or university logos, handwritten notes, etc. The resulting image is not "jaggy" like a bitmap, but smooth. Then it can then be rendered at any resolution.
Potrace can currently produce the following output formats: SVG, PDF, EPS, PostScript, DXF, GeoJSON, PGM (for easy antialiasing of pixel-based images), Gimppath, and XFig. In this article, we'll show you how to use potrace to vectorize a signature from a camera photo with the CLI using a simple command.
1. Download Potrace
As first step, in case that you don't have potrace installed on your system (Windows or Unix based), you will need to acquire its binaries:
In environments like Ubuntu or CentOS is pretty easy to install with the command line and it will be immediately available from the command line as potrace. In Windows you will need to use the executable for the command with the full path:
"C:\\Program Files\\potrace\\potrace.exe" --svg signature.bmp -o signature.svg
Or make the path where potrace is extracted from the zip available from the path. For more information about potrace, don't forget to visit the official website here.
2. Convert your JPEG/PNG image to BMP
As next step, you only need an image of a signature from a photo, for example:
However, potrace needs an image in the Bitmap format. So be sure to convert your image to BMP using some tool like Imagick or an online tool.
3. Vectorize to SVG with Potrace
Finally, proceed to vectorize your BMP image with potrace with the following command:
REM Vectorize image with a simple command potrace --svg signature.bmp -o signature.svg
Note that with big images or when using directly from the CLI without automation (using potrace from a script in another programming language), you can display the progress of the vectorization adding the
potrace --svg --progress signature.bmp -o signature.svg
Which outputs a simple progress bar:
Remember that Potrace works from BMP to SVG and other formats as PDF, however SVG is the standarized way to do it because you can use another tools as Imagick to convert it from SVG to PNG with transparency easily. For a detailed tutorial and description about all the options available of Potrace, don't forget to check the man page of potrace here.
The result of the previous command will be the output file, that in this case is
signature.svg that contains our original image into a pretty nice vectorized result:
In this way with this tool, you will be able to save some dollars of cost when you pay to a graphic designer to digitize some client signature.
Happy coding !
Become a more social person