Potrace is a tool for tracing a bitmap, which means, transforming a bitmap into a smooth, scalable image. The input is 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. It can then be rendered at any resolution.
## 1. Basic bitmap → SVG
Convert a black-and-white bitmap (PBM/PGM/PPM/BMP) to SVG.
```bash
potrace input.pbm -o output.svg
```
---
## 2. Specify output format explicitly
Force SVG output (useful in scripts).
```bash
potrace input.pbm --svg -o output.svg
```
---
## 3. Convert PNG (via ImageMagick)
`potrace` doesn't read PNG directly---pipe it through `convert`.
```bash
convert logo.png -threshold 50% logo.pbm
potrace logo.pbm -o logo.svg
```
---
## 4. Invert black/white interpretation
Treat white as foreground instead of black.
```bash
potrace input.pbm --invert -o output.svg
```
---
## 5. Smooth curves (reduce jagged edges)
Increase curve optimization.
```bash
potrace input.pbm --opttolerance 0.2 -o smooth.svg
```
---
## 6. Disable curve optimization (pixel-perfect tracing)
Useful for pixel art.
```bash
potrace input.pbm --optcurve false -o pixel.svg
```
---
## 7. Set corner detection threshold
Lower values preserve sharp corners.
```bash
potrace input.pbm --alphamax 0.5 -o sharp.svg
```
---
## 8. Remove small speckles (despeckle)
Ignore tiny artifacts under N pixels.
```bash
potrace input.pbm --turdsize 10 -o clean.svg
```
---
## 9. Set SVG fill color
Embed a specific fill color in the output.
```bash
potrace input.pbm --svg --color "#000000" -o black.svg
```
---
## 10. Transparent background SVG
No background rectangle.
```bash
potrace input.pbm --svg --opaque false -o transparent.svg
```
---
## 11. Output EPS (for print workflows)
Common for LaTeX and publishing.
```bash
potrace input.pbm --eps -o output.eps
```
---
## 12. Output PDF
Useful for sharing or printing.
```bash
potrace input.pbm --pdf -o output.pdf
```
---
## 13. Batch convert multiple images
Loop through a directory of bitmaps.
```bash
for f in *.pbm; do
potrace "$f" -o "${f%.pbm}.svg"
done
```
---
## 14. High-quality trace for scanned drawings
A good all-around combo for hand-drawn art.
```bash
potrace scan.pbm \
--opttolerance 0.1 \
--alphamax 1.0 \
--turdsize 20 \
-o drawing.svg
```
---
## 15. End-to-end PNG → SVG (single command)
No intermediate file left behind.
```bash
convert sketch.png -threshold 55% pbm:- | potrace - -o sketch.svg
```
---
### Commonly Tuned Options (Quick Reference)
| Option | Purpose |
| ---------------- | ---------------------------- |
| `--opttolerance` | Curve smoothing strength |
| `--alphamax` | Corner sharpness |
| `--turdsize` | Remove small blobs |
| `--invert` | Swap foreground/background |
| `--optcurve` | Enable/disable curve fitting |
| `--color` | SVG fill color |
| `--opaque` | Background control |