点这里,搜索淘宝优惠券!
点这里,搜索淘宝优惠券!

python 二维码的生成与解析-QrCode +ZbarLight

环境

系统:Ubuntu 16.04
Python:2.7.12

参考文档:官方说明:https://pypi.org/project/qrcode/

安装QrCode

pip install qrcode[pil]

生成二维码

import qrcode
qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,
)
qr.add_data('Some data')
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")
img.save(file_name

安装ZbarLight:https://pypi.org/project/zbarlight/

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

解析二维码

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

有库的感觉就是好!

 

posted @ 2018-10-17 10:03  chd_ailex  阅读(360)  评论(0编辑  收藏  举报