Skip to main content

potrace Python bindings

Project description

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

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

Make sure you have the agg and potrace development packages installed (libagg-dev and libpotrace-dev on ubuntu) and run:

python setup.py install

Building on 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:j

  • “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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypotrace-0.1.1.tar.gz (196.3 kB view details)

Uploaded Source

File details

Details for the file pypotrace-0.1.1.tar.gz.

File metadata

  • Download URL: pypotrace-0.1.1.tar.gz
  • Upload date:
  • Size: 196.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pypotrace-0.1.1.tar.gz
Algorithm Hash digest
SHA256 58662529a7b701de85d83a8911b17195fd833cde18ddb1cb4088e36e406c9e49
MD5 155a2fb066db5cc204863a06ce935363
BLAKE2b-256 1fa68d20d5fc78cd1fadaafcfd3bf0315089756560dbf590b413607bcad8dcb1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page