My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

Elaphe

WARNING! trunk is broken for complete rewriting. For working version, grab 0.5.3 in /tags.

Elaphe is a python binding for the Barcode Writer In Pure PostScript (http://www.terryburton.co.uk/barcodewriter/). It is a thin-wrapper which employs Python Imaging Library as PostScript rendering interface.

Requirements

  • Python 2.5 or later (functional decorators, ternary operator, and
  • generator expressions are used).
  • If you want to render the generated barcode, Python Imaging Library
  • (http://www.pythonware.com/products/pil) is required under the condition that EpsImagePlugin is enabled (i.e. at least you must have Ghostscript is installed and callable from PIL).

Simple Usage

The following example:

  >>> from elaphe import barcode
  >>> barcode('qrcode',
  ...         'Hello Barcode Writer In Pure PostScript.',
  ...         options=dict(version=9, eclevel='M'), 
  ...         margin=10, data_mode='8bits'))   # Generates PIL.EpsImageFile instance
  <PIL.EpsImagePlugin.EpsImageFile instance at ...>
  >>> _.show()            # Show the image

should invoke default viewer which shows a QRcode symbol with 10px margin.

Remember, barcode() returns PIL image object.

Frequently Issued Problems

Trunk does not work

No problem, trunk is broken. Use /tags/0.5.3.

IOError: 32 Broken pipe

If you see, especially on Windows, something like:

File ".../PIL/EpsImagePlugin.py", line 72, in Ghostscript
    gs.write(s)
IOError: [Errno 32] Broken pipe

Make sure Ghostscript is installed as well as environment variable PATH is set.

Try following code on your enviroment:

# coding: utf-8                                                                 
from StringIO import StringIO
from PIL.EpsImagePlugin import EpsImageFile

src = """%!PS-Adobe 2.0                                                         
%%BoundingBox: 0 0 144 144                                                      
36 36 72 72 rectfill                                                            
/Courier findfont 12 scalefont setfont                                          
36 120 moveto (text) show                                                       
showpage                                                                        
"""

im = EpsImageFile(StringIO(src))
im.save('foo.png')

If PIL and Ghostscript are correctly installed, you will see square and text in 'foo.png'.

Plan

Elaphe will make use of reportlab.graphics.renderFooBar instead of bwipp/gs/PIL.

Powered by Google Project Hosting