Skip to content

Barcode rendering for Python 2 and 3 supporting QRcode, Aztec, PDF417, I25, Code128, Code39 and many more types.

License

Notifications You must be signed in to change notification settings

timeoutdigital/treepoem

 
 

Repository files navigation

Treepoem

A cleverly named, but very simple python barcode renderer wrapping the BWIPP library and ghostscript command line tool, Python 2.7 and 3.3+ compatible.

Installation

Install from pip:

pip install treepoem

You'll also need Ghostscript installed. On Ubuntu/Debian this can be installed with:

apt-get install ghostscript

On Mac OS X use:

brew install ghostscript

Otherwise refer to your distribution's package manager, though it's likely to be called ghostscript too.

API

generate_barcode(barcode_type, data, options=None)

Generates a barcode and returns it as a PIL image file object (specifically, a PIL.EpsImagePlugin.EpsImageFile).

barcode_type is the name of the barcode type to generate (see below).

data is the string of data to embed in the barcode - the amount that can be embedded varies by type.

options is a dictionary of strings-to-strings of extra options to be passed to BWIPP, as per its docs.

For example, this generates a QR code image, and saves it to a file using standard PIL Image.save():

>>> import treepoem
>>> image = treepoem.generate_barcode(
...     barcode_type='qrcode',  # One of the BWIPP supported codes.
...     data='barcode payload',
... )
>>> image.convert('1').save('barcode.png')

If your barcode image is monochrome, with no additional text or coloring, converting the Image object to monochrome as shown above (image.convert('1')) will likely reduce its file size.

barcode_types

This is a set of the ~100 names of the barcode types that the vendored version of BWIPP supports. If you're looking for whether a specific type is supported, check here.

The library is tested with these specific, common types:

Command-line interface

Treepoem also includes a simple command-line interface to the functionality of generate_barcode. For example, these commands will generate two QR codes with identical contents, but different levels of error correction (see QR Code Options):

$ treepoem -o barcode1.png -t qrcode "This is a test" eclevel=H
$ treepoem -o barcode2.png -t qrcode "^084his is a test" eclevel=L parse

Complete usage instructions are shown with treepoem --help.

What's so clever about the name?

Barcode.

Bark ode.

Tree poem.

About

Barcode rendering for Python 2 and 3 supporting QRcode, Aztec, PDF417, I25, Code128, Code39 and many more types.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PostScript 99.1%
  • Python 0.9%