Skip to main content

These bindings provide an object oriented API to the potrace library.

The full API documentation is on https://pythonhosted.org/pypotrace/.

Example usage

The bindings work with input images represented as numpy arrays:

import numpy as np
import potrace

# Make a numpy array with a rectangle in the middle
data = np.zeros((32, 32), np.uint32)
data[8:32-8, 8:32-8] = 1

# Create a bitmap from the array
bmp = potrace.Bitmap(data)

# Trace the bitmap to a path
path = bmp.trace()

# Iterate over path curves
for curve in path:
    print "start_point =", curve.start_point
    for segment in curve:
        print segment
        end_point_x, end_point_y = segment.end_point
        if segment.is_corner:
            c_x, c_y = segment.c
        else:
            c1_x, c1_y = segment.c1
            c2_x, c2_y = segment.c2

Installation

Ubuntu

Install system dependencies:

$ sudo apt-get install build-essential python-dev libagg-dev libpotrace-dev pkg-config

Install pypotrace:

$ git clone https://github.com/flupke/pypotrace.git
$ cd pypotrace
$ pip install numpy
$ pip install .

CentOS/RedHat

Install system dependencies:

$ sudo yum -y groupinstall "Development Tools"
$ sudo yum -y install agg-devel potrace-devel python-devel

Install pypotrace:

$ git clone https://github.com/flupke/pypotrace.git
$ cd pypotrace
$ pip install numpy
$ pip install .

OSX

Install system dependencies:

$ brew install libagg pkg-config potrace

Install pypotrace:

$ git clone https://github.com/flupke/pypotrace.git
$ cd pypotrace
$ pip install numpy
$ pip install .

Windows

Thanks to klonuo for the instructions

Here are instruction how to make this package work on Windows, by using MinGW system. Probably it can be done with Visual Studio, but I lack skills to make such magic.

So assuming user has MinGW available, additional two packages are needed:

  1. potrace source: http://potrace.sourceforge.net/#downloading

  2. agg source: http://www.antigrain.com/download/index.html

I extracted both packages in my C:\src folder. Both are easy to build by executing ./configure; make and ./autogen.sh; make respectively, on MSYS prompt.

After that, we need some variables to build pypotrace successfully:

First, includes paths:

  • “numpy/arrayobject.h”: C:/Python27/Lib/site-packages/numpy/core/include

  • potrace headers: C:/src/potrace-1.11/src

  • agg headers: C:/src/agg-2.5

there is a little catch for agg includes, as paths referenced in cpp sources point to agg2/*.h while in downloaded agg package we don’t have agg2 folder. For me it was easiest to rename C:/src/agg-2.5/include to C:/src/agg-2.5/agg2 and use C:/src/agg-2.5 as agg include folder.

Next, libdirs for libraries we build above:

  • potrace: C:/src/potrace-1.11/src/.libs

  • agg: C:/src/agg-2.5/src

and we can make pypotrace build command, and execute it:

python setup.py build_ext -IC:/Python27/Lib/site-packages/numpy/core/include;C:/src/potrace-1.11/src;C:/src/agg-2.5 -LC:/src/potrace-1.11/src/.libs;C:/src/agg-2.5/src

Finally install the package:

C:\src\git\pypotrace>python setup.py install
running install
running build
running build_py
copying potrace\__init__.py -> build\lib.win32-2.7\potrace
copying potrace\agg\__init__.py -> build\lib.win32-2.7\potrace\agg
running build_ext
skipping 'potrace\_potrace.c' Cython extension (up-to-date)
skipping 'potrace\bezier.cpp' Cython extension (up-to-date)
skipping 'potrace/agg\curves.cpp' Cython extension (up-to-date)
running install_lib
creating C:\Python27\Lib\site-packages\potrace
creating C:\Python27\Lib\site-packages\potrace\agg
copying build\lib.win32-2.7\potrace\agg\curves.pyd -> C:\Python27\Lib\site-packages\potrace\agg
copying build\lib.win32-2.7\potrace\agg\__init__.py -> C:\Python27\Lib\site-packages\potrace\agg
copying build\lib.win32-2.7\potrace\bezier.pyd -> C:\Python27\Lib\site-packages\potrace
copying build\lib.win32-2.7\potrace\_potrace.pyd -> C:\Python27\Lib\site-packages\potrace
copying build\lib.win32-2.7\potrace\__init__.py -> C:\Python27\Lib\site-packages\potrace
byte-compiling C:\Python27\Lib\site-packages\potrace\agg\__init__.py to __init__.pyc
byte-compiling C:\Python27\Lib\site-packages\potrace\__init__.py to __init__.pyc
running install_egg_info
Writing C:\Python27\Lib\site-packages\pypotrace-0.1-py2.7.egg-info

Running tests

You can check everything is working correctly by running the tests:

$ pip install '.[dev]'
$ nosetests -v

Documentation

The documentation is hosted here: http://packages.python.org/pypotrace

A copy is also included in the doc/_build/html directory of the source distribution.

Homepage

This project is hosted on github: http://github.com/flupke/pypotrace

Metadata

Release files for pypotrace-windows 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypotrace-windows 0.2
File Size Uploaded
pypotrace-windows-0.2.tar.gz 182.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pypotrace-windows 0.2
File Interpreter ABI Platform
pypotrace_windows-0.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pypotrace_windows-0.2-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
pypotrace_windows-0.2-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details

Total release size: 678.4 kB

Release files / pypotrace-windows-0.2.tar.gz

Download URL pypotrace-windows-0.2.tar.gz
Size 182.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1957de55e3639ab33ba857598e256502ae9a8eba2710f568fd09688446e20725
BLAKE2b-256 checksum
How to use checksums
d0927f9151e3bccc4fc201f72227ce3b09fbef078a33cb3c4ea9798c0e29794b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.7

Release files / pypotrace_windows-0.2-cp310-cp310-win_amd64.whl

Download URL pypotrace_windows-0.2-cp310-cp310-win_amd64.whl
Size 164.3 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
c0dbf5f0d97e581d4e3ea3b7d92799e75a3cfb524a22951c013f30b3030dc009
BLAKE2b-256 checksum
How to use checksums
4ca3a7f197ace3f501b52fba694a2b7a5f8c3fe8e06e8023d1d5e63d033e6685
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.7

Release files / pypotrace_windows-0.2-cp39-cp39-win_amd64.whl

Download URL pypotrace_windows-0.2-cp39-cp39-win_amd64.whl
Size 165.6 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
b8eb467f8117ffe0e9c34e89a3ef0c495c6f7cbef1e813ffb415826dfa3ff2a0
BLAKE2b-256 checksum
How to use checksums
4d575e933f99011de4873ebde0516c9657c87be258beb66aefc06bd5ed6f384a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.7

Release files / pypotrace_windows-0.2-cp38-cp38-win_amd64.whl

Download URL pypotrace_windows-0.2-cp38-cp38-win_amd64.whl
Size 165.9 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
f624da9a14313bdad927bd09d2e4f56c6bebaa5f78c198e4520bd46de775b2e2
BLAKE2b-256 checksum
How to use checksums
bfa3ad7a682d0edbfc59b64148c1d523ac5bb5b5db33b4dafc6fa8108e539c79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.7

Release history Release notifications | RSS feed

This release

0.2 This release

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page