标签:hub this sample decode tor 视觉 enc lin pip
pyStrich is a Python module to generate 1D and 2D barcodes. Currently it supports:
pip install pyStrich
from pystrich.ean13 import EAN13Encoder
encoder = EAN13Encoder("690123456789")
encoder.save("pyStrich.png")
from pystrich.datamatrix import DataMatrixEncoder
encoder = DataMatrixEncoder("This is a DataMatrix.")
encoder.save( "sample_barcodes/datamatrix_test.png" )
print(encoder.get_ascii())
from pystrich.code39 import Code39Encoder
from pystrich.code128 import Code128Encoder
from pystrich.datamatrix import DataMatrixEncoder
from pystrich.ean13 import EAN13Encoder
from pystrich.qrcode import QRCodeEncoder
The libdmtx DLLs are included with the Windows Python wheels. On other operating systems, you will need to install the libdmtx shared library.
- Mac OS X:
brew install libdmtx
- Linux:
sudo apt-get install libdmtx0a
Install this Python wrapper; use the second form to install dependencies of the read_datamatrix
and write_datamatrix
command-line scripts:
pip install pylibdmtx
pip install pylibdmtx[scripts]
If you see an ugly ImportError when importing pylibdmtx on Windows you will most likely need the Visual C++ Redistributable Packages for Visual Studio 2013
.
Install vcredist_x64.exe if using 64-bit Python, vcredist_x86.exe if using 32-bit Python.
The encode function generates an image containing a Data Matrix barcode:
>>> from pylibdmtx.pylibdmtx import encode
>>> encoded = encode(‘hello world‘.encode(‘utf8‘))
>>> img = Image.frombytes(‘RGB‘, (encoded.width, encoded.height), encoded.pixels)
>>> img.save(‘dmtx.png‘)
>>> print(decode(Image.open(‘dmtx.png‘)))
>>> from pylibdmtx.pylibdmtx import decode
>>> from PIL import Image
>>> decode(Image.open(‘pylibdmtx/tests/datamatrix.png‘))
[Decoded(data=‘Stegosaurus‘, rect=Rect(left=5, top=6, width=96, height=95)),
Decoded(data=‘Plesiosaurus‘, rect=Rect(left=298, top=6, width=95, height=95))]
pip install qrcode
qr ‘Some data‘ > test.png
import qrcode
img = qrcode.make("xinxingzhao")
img.save("xinxing.png")
上面两种方式都是按照qrcode默认的方式生成二维码,如果我们希望生成不同尺寸的二维码就需要使用QRCode类了。
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")
version
表示二维码的版本号,二维码总共有1到40个版本,最小的版本号是1,对应的尺寸是21×21,每增加一个版本会增加4个尺寸。这里说的尺寸不是只生成图片的大小,而是值二维码的长宽被平均分为多少份。
error_correction
指的是纠错容量,这就是为什么二维码上面放一个小图标也能扫出来,纠错容量有四个级别,分别是:
box_size 指的是生成图片的像素
border 表示二维码的边框宽度,4是最小值
支持的码制列表:
缺点:没有画出EAN13的起始符和终止符。
支持识别二维码?
标签:hub this sample decode tor 视觉 enc lin pip
原文地址:https://www.cnblogs.com/brt2/p/13204632.html