Skip to main content

A simple zbar wrapper

Project description

ZbarLight

zbarlight is a simple wrapper for the zbar library. For now, it can read all zbar supported codes. Contributions, suggestions and pull requests are welcome.

zbarlight is compatible with Python 2 and Python 3.

zbarlight is hosted on Github at <https://github.com/Polyconseil/zbarlight/>.

Installation

You need to install ZBar Bar Code Reader <http://zbar.sourceforge.net/> and its headers before installing zbarlight.

On Debian

$ apt-get install libzbar0 libzbar-dev
$ pip install zbarlight  # you can also use setuptools directly

On Mac OS X

$ brew install zbar
$ export LDFLAGS="-L$(brew --prefix zbar)/lib"
$ export CFLAGS="-I$(brew --prefix zbar)/include"
$ pip install zbarlight

On Windows

Instruction can be found on <https://gist.github.com/Zephor5/aea563808d80f488310869b69661f330>.

How To use ZbarLight

from PIL import Image
import zbarlight

file_path = './tests/fixtures/two_qr_codes.png'
with open(file_path, 'rb') as image_file:
    image = Image.open(image_file)
    image.load()

codes = zbarlight.scan_codes(['qrcode'], image)
print('QR codes: %s' % codes)

Troubleshooting

In some case zbarlight will not be able to detect the 1D or 2D code in an image, one of the known cause is that the image background color is the same as the foreground color after conversion to grey scale (it’s happen on images with alpha channel). You can use the copy_image_on_background function to add a background color on your image.

from PIL import Image
import zbarlight

file_path = './tests/fixtures/two_qr_codes.png'
with open(file_path, 'rb') as image_file:
    image = Image.open(image_file)
    image.load()

new_image = zbarlight.copy_image_on_background(image, color=zbarlight.WHITE)  # <<<<<<<<<<<<<<<< Add this line <<<<
codes = zbarlight.scan_codes(['qrcode'], new_image)
print('QR codes: %s' % codes)

Some other cases without known solutions are show in the scan_codes() tests (search for the expected failures). Any clues on these cases is welcome.

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

zbarlight-2.3.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file zbarlight-2.3.tar.gz.

File metadata

  • Download URL: zbarlight-2.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for zbarlight-2.3.tar.gz
Algorithm Hash digest
SHA256 9ddb37751121b8e575277b312510bd3d08839b4b465a42b873e8e25344b26698
MD5 6bbaa5ea5aa3aacaef1d23adead67ead
BLAKE2b-256 3deede1466b1170e347d185dc0c3f75c1100fab03bb2a9544f142bb5bbccd182

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