Python generates QR codes. common modules include pyqrencode and qrcode.
1. Use the pyqrencode module to generate a QR code
Installing the pyqrencode module is complex and relies on many things. The following installation process is summarized after testing:
1. Download Cython: https://pypi.python.org/packages/source/C/Cython/Cython-0.19.1.tar.gz
Install: tar-zxf Cython-0.19.1.tar.gz & cd Cython-0.19.1 & python setup. py install
2. Download qrencode: http://fukuchi.org/works/qrencode/qrencode-3.4.2.tar.gz
Install yum install libpng-devel-y before installation
Installation: tar-zxf qrencode-3.4.2.tar.gz & cd qrencode-3.4.2 &./configure & make install
3, download Imaging: http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
Install: tar-zxf Imaging-1.1.7.tar.gz & cd Imaging-1.1.7 & python setup. py install
4. Download: https://codeload.github.com/bitly/pyqrencode/zip/master
Installation:
Unzip-q pyqrencode-master.zip
Cd pyqrencode-master
Easy_install cython
Cython qrencode. pyx
Python setup. py install
Echo "/usr/local/lib">/etc/ld. so. conf
Ldconfig
5. Use pyqrencode to generate a QR code
>>> From qrencode import Encoder
>>> Encoder = Encoder ()
>>> Img = encoder. encode ("hello python! ", {'Width': 300 })
>>> Img. save ("char.png ")
Char.png is the generated QR code file.
Ii. Use the qrcode module to generate a QR code
1. Download: https://pypi.python.org/packages/source/q/qrcode/qrcode-2.0.tar.gz
2. Installation: tar-zxf qrcode-2.0.tar.gz & cd qrcode-2.0 & python setup. py install
3. Use qrcode to generate a QR code
>>> Import qrcode
>>> Q = qrcode. main. QRCode ()
>>> Q. add_data ("hello python! ")
>>> Q. make ()
>>> M = q. make_image ()
>>> M.save('char.png ')
3. QR code recognition
The zbar module is used to parse the QR code. The change module is directly installed in the exe file under windowns, which is relatively simple. There are many dependent packages in linux, so the installation process is not described. The usage is as follows:
def get_QR(): scanner = zbar.ImageScanner() scanner.parse_config("enable") pil = Image.open("char.png").convert('L') width, height = pil.size raw = pil.tostring() image = zbar.Image(width, height, 'Y800', raw) scanner.scan(image) data = '' for symbol in image: data+=symbol.data del(image) return data
Data is two-dimensional content.