GithubHelp home page GithubHelp logo

elaphe's Introduction

Elaphe

Elaphe is a python binding of Barcode Writer In Pure PostScript (http://www.terryburton.co.uk/barcodewriter/). It generates barcode symbol as PostScript code fragment using BWIPP. The generated code is then embedded in encapsulated PostScript image which can be handled by PIL.

Prerequisites

  • Python 2.7 or later (functional decorators, ternary operator, and generator expressions are used).

    Note

    Except setup.py test, code may still work on 2.5-2.6.

  • If you want to render barcode into bitmap image, EpsImagePlugin of Python Imaging Library (http://www.pythonware.com/products/pil) or Pillow is required. Note that EpsImagePlugin requires Ghostscript is correctly installed.

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 ... at ...>
>>> _.show() # Show rendered bitmap

will invoke some viewer which shows a QRcode symbol with 10px margin.

Remember, barcode() returns PIL image object.

elaphe's People

Contributors

whosaysni avatar graingert avatar buhtigithub avatar todoa2c avatar danpalmer avatar tavva avatar peterjclaw avatar

Stargazers

Nikolaus Schlemm avatar Maxim Stolyarchuk avatar Geoffrey avatar  avatar Gustavo Dagostin da Silva avatar zxyqwe avatar Robert avatar Osvaldo Santana Neto avatar

Watchers

 avatar James Cloos avatar

elaphe's Issues

Provide wheels

Thanks for providing this useful project, would it be possible to provide wheels on PyPI for releases? They speed up install times for consumers as they remove the need to run code locally as part of the install.

QR code: "ValueError: No appropriate mode"

Please add the following patch, which fixes a typo in eclevel to ecval conversion:

--- elaphe/qrcode.py~   2017-05-03 18:50:22.000000000 +0200
+++ elaphe/qrcode.py    2018-03-12 12:30:58.957870018 +0100
@@ -264,7 +264,7 @@
         n_msgbits = len(mid)+cclen+n_msgbits
 
     # logging.debug('enc=%s fmt=%s eclv=%s ver=%s' % (encoding, format_, eclevel, version))
-    ecval = 'LHQM'.index(eclevel)
+    ecval = 'LMQM'.index(eclevel)
     if version:
         version = str(version)
     for frmt, vers, size, asp2, asp3, nmod, ecws_list, ecb_list in QRCODE_METRIC:

See also:
https://bitbucket.org/whosaysni/elaphe/issues/81/valueerror-no-appropriate-mode-when-using

pharmacode bbox not calcualted correctly

Hey,

Wanted a pharmacode barcode on labels and landed on this package. But when testing the biggest number possible (131070) I was missing some bars.

 bar = barcode('pharmacode', '131070')
bar.save('elaphe_test_1.jpg')
bar = barcode('pharmacode', '131070', right_margin = 50)
bar.save('elaphe_test_2.jpg')

elaphe_test_1
elaphe_test_2

So looking at the code I first looked at how the widths are defined.

default_options = dict(
            LinearCodeRenderer.default_options,
            height=8*2.835, nwidth=0.5*2.835,
            wwidth=1.5*2.835, swidth=1.0*2.835,
            textyoffset=-7, textsize=10)

These are converted from DPI to DPmm. Was afraid rounding off is a problem. But changing it to intiger values only made the issue worse.

Next looked at the code_box calculation.

def _code_bbox(self, codestring):
            """
            >>> r = Phamacode._Renderer({})
            >>> r._code_bbox('117480')
            [0, 0, 90.72, 22.68]
            """
            return [0, 0, int(math.log(int(codestring), 2))*2*2.835,
                    self.lookup_option('height')]

Here the DPI to DPmm is done again. But when the bar width is changed this is not considered. The main issue is the *2 though. The code here multiplies the number of bars by 2 while they can either be 0.5+1 or 1.5+1 ( +1 for spacer).

Hope this can be fixed.

Render tests fail

Run python setup.py test -s test.render.suite; it's not clear whether these errors are important or not.

Error when generating Code39 barcode containing *

Example:

import io
import elaphe

b = elaphe.barcode('code39', 'ABC*DEF')
b.save(io.BytesIO(), format='png')

Results in:

CalledProcessError: Command '['gs', '-q', '-g144x72', '-r72.000000x72.000000', '-dBATCH', '-dNOPAUSE', '-dSAFER', '-sDEVICE=ppmraw', '-sOutputFile=/tmp/tmp2njjh_ze', '-c', '0 0 translate', '-f', '/tmp/tmp4y2j7fa5', '-c', 'showpage']' returned non-zero exit status 1.

with stderr:

Error: /bwipp.code39badCharacter in null
Additional information: (Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%)
Current allocation mode is local
GPL Ghostscript 9.50: Unrecoverable error, exit code 1

Yet * is included in elaphe.code39.CODE39_CHARS.

Render tests error on Python 3

Run python setup.py test -s test.render.suite on Python 3, these error around the use of StringIO which no longer exists.

Since these also fail under Python 2 (#8) it's not clear whether this is a quick fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.