AutoTrace is a utility for converting bitmap into vector graphics. AutoTrace can be compiled standalone, then it can import pnm, pbm, pgm, ppm, bmp and tga files. If you have installed libpng you can also read png files and with ImageMagick a very broad range of input formats is available.
In this article, we will explain you how to easily build autotrace in Ubuntu 18.04.
1. Install dependencies
In order to build the autotrace utility from scratch, you will need the following libraries installed on your system:
intltool
: intltool is a set of tools to centralize translation of many different file formats using GNU gettext-compatible PO files.imagemagick
: ImageMagick, is a software suite to create, edit, and compose bitmap images.libmagickcore-dev
: This package included header files and static libraries needed to compile programs using MagickCore.pstoedit
: pstoedit is a free computer program that converts PostScript and PDF files to other vector formats.libpstoedit-dev
: pstoedit is a framework for converting Postscript and PDF files to various editable vector graphic formats.autopoint
: The autopoint program is part of GNU gettext, a set of tools for translating programs into different languages.
You can install them easily in Ubuntu 18.04 with the following command:
sudo apt install intltool imagemagick libmagickcore-dev pstoedit libpstoedit-dev autopoint
The installation of the mentioned packages will take ~240MB of space in your disk. Once you install the dependencies, we may proceed with the build of autotrace.
2. Clone autotrace source code
As next step, you will need to clone the source code of autotrace. You can directly obtain it with git running the following command in your terminal:
git clone https://github.com/autotrace/autotrace.git
Once it has been cloned, change to the autotrace directory:
cd autotrace
And proceed with the next step. For more information about the autotrace utility, please visit the official repository at Github here.
3. Generate the configure script
Now you will need to generate the configure script running the autogen file in the root directory of autotrace like this:
./autogen.sh
Then specify that the autotrace content should be placed into /usr/{bin,lib,share,include} with the following command:
LD_LIBRARY_PATH=/usr/local/lib ./configure --prefix=/usr
This should make autotrace accessible from the CLI once you build it.
4. Build and install
Finally, all you need to do is to run the make command on the directory:
make
And then install the files in the proper directory with make install:
make install
5. Using the autotrace CLI
All you have left after building and installing the tool is to test it. You can easily check the version of the built with the following command:
autotrace -v
Which should output something similar to: AutoTrace version 0.40.0.
The autotrace CLI options are defined like this:
autotrace [-background-color hexvalue] [-centerline] [-color-count int] [-corner-always-
threshold angle] [-corner-surround int] [-corner-threshold angle] [-despeckle-level
int] [-despeckle-tightness real] [-dpi int] [-error-threshold real] [-filter-iterations
int] [-help] [-input-format format] [-line-reversion-threshold real] [-line-threshold
real] [-list-input-formats] [-list-output-formats] [-log] [-output-file file] [-output-
format format] [-preserve-width] [-remove-adjacent-corners] [-report-progress] [-debug-
arch] [-debug-bitmap] [-tangent-surround int] [-version] [-width-factor real] inputfile
The definition of what every options does is shown on the following list:
-background-color hexvalue
: Employ the color specified by the hexadecimal code hexcode as the background that should be ignored, for example FFFFFF (default: no background color).-centerline
: Trace an object's centerline (default: employ its outline).-color-count int
: Reduce the bitmap to using the number of colors specified by the unsigned integer int (range: 1-256). The default value of 0 indicates that no color reduction is to be done. Does not work with grayscale images.-corner-always-threshold angle
: Consider any angle at a pixel which falls below the specified angle (in degrees) as a corner, even if it is bordered by other corner pixels (default: 60).-corner-surround int
: Consider the specified number of pixels on either side of a point when determining if that point is a corner (default: 4).-corner-threshold angle
: Consider any pixel which forms an angle with its predecessor(s) and successor(s) that is smaller than the specified angle (in degrees) as a corner (default: 100).-despeckle-level int
: Employ the specified integer (range: 1-20) as the value for despeckling (default: no despeckling).-despeckle-tightness real
: Employ the specified real number (range: 0.0-8.0) as the value for despeckle tightness (default: 2.0).-dpi int
: The dots per inch value in the input image, affects scaling of mif output image.-error-threshold real
: Subdivide fitted curves that are offset by a number of pixels exceeding the specified real number (default: 2.0).-filter-iterations int
: Smooth the curve the specified number of times prior to fitting (default: 4).-help
: Print a help message and exit.-input-format format
: Employ the specified input format, where format is one of:- BMP (Windows bitmap format)
- PBM (Portable BitMap format)
- PGM (Portable Graymap format)
- PNM (Portable Anymap format)
- PPM (Portable Pixmap format)
- TGA (Targa format)
- The supported input formats are determined when the application is built and depend upon the availability of other software (the -list-input-formats command can be used to determine which are supported locally).
-line-reversion-threshold real
: When a spline is closer to a straight line than the specified real number weighted by the square of the curve length (default: .01), maintain it as a straight line, even if it is a list with curves.-line-threshold real
: If a spline does not deviate from the straight line defined by its endpoints by more than the specified number of pixels, then treat it as a straight line (default: 1).-list-input-formats
: Send a list of the supported input formats to stderr.-list-output-formats
: Send a list of the supported output formats to stderr.-log
: Send a detailed progress report to the file inputfile.log.-output-file file
: Send the output to the specified file.-output-format format
: Employ the specified output format, where format is one of:- ai(Adobe Illustrator)
- cgm(Computer Graphics Metafile)
- dr2d(IFF DR2D format, used almost exclusively on Amiga platforms)
- dxf(AutoCAD Drawing Exchange format)
- emf(Windows Enhanced Metafile format)
- epd(Encapsulated Vectorial Graphics format)
- eps(Encapsulated PostScript)
- er(Elastic Reality Shape format)
- fig(xfig (1) 3.2)
- mif(FrameMaker MIF format)
- pdf(Portable Data Format)
- p2e(pstoedit (1) frontend)
- sk(Sketch)
- svg(Scalable Vector Graphics)
- swf(Shockwave Flash 3)
- The supported output formats are determined when the application is built and depend upon the availability of other software (the -list-output-formats command can be used to determine which are supported locally).
-preserve-width
: Whether to preserve line width prior to thinning.-remove-adjacent-corners
: Remove adjacent corners.-report-progress
: Report tracing status in real time.-debug-arch
: Print the type of cpu.-debug-bitmap
: Dump loaded bitmap to <input_name>.bitmap.\-tangent-surround int
: Consider the specified number of points to either side of a point when computing the tangent at that point (default: 3).-version
: Print the version number of the program and exit.-width-factor real
: Weight factor for fitting the linewidth.
For example, in order to simply vectorize a BMP file, you may simply run the following command, replacing the input file path (bear.bmp) and the output file path (bear.svg):
autotrace -input-format bmp -output-format svg -output-file bear.svg bear.bmp
Happy coding ❤️!