小言_互联网的博客

python生成条形码

735人阅读  评论(0)

 

介绍一个码制比较全的库:treepoem

treepoem的突出之处在于它所支持的符号和符号变体的数量。

然而,实现这一壮举的方式也带来了一些可能的负面影响。 Python包treepoem是Postscript程序BWIPP的一个包装。treepoem使用subprocess. popen()调用Postscript,这意味着Postscript必须已经安装并且子进程可用。如果您试图在共享环境(如notebook服务器)中生成条形码图像(仅举一个例子),那么这可能是一个问题。

 

Package last updated License Python versions UPC-A EAN-13 ISBN PZN I. 2 of 5 Code 39 Code 93 Code 128 Datamatrix PDF417 QR Micro QR Aztec Output
treepoem Aug 2018 MIT 28 2, 3 req. Pillow

 直接上代码(python3)

Code128


import treepoem

image = treepoem.generate_barcode(
    barcode_type='code128',  #  BWIPP 支持的码制.
    data="^FNC3"+barcode_content,  #^FNC3为指定非数据函数字符,正常字符串不需要
    options={"includetext": includetext,"parsefnc":True,"height":0.5}    #parsefnc为解析非数据函数字符,正常字符串不需要
            )
#条码保存
#如果您的条形码图像是单色的,没有额外的文本或颜色,将图像对象转换为如上所示的单色(image.convert('1'))可能会减少其文件大小。
image.convert('1').save('barcode.png')

Data Matrix

import treepoem

image = treepoem.generate_barcode(
    barcode_type='datamatrix',  #  BWIPP 支持的码制.
    data="^PROG"+barcode_content,  #^PROG为指定非数据函数字符,正常字符串不需要
    options={"parsefnc":True}    #parsefnc为解析非数据函数字符,正常字符串不需要
            )
#条码保存
image.convert('1').save('barcode.png')

资料来源:

其他支持python的生成条形码库

https://jonemo.github.io/neubertify/2019/01/23/barcode-generation-python/

Code 128 BWIPP 规则

https://github.com/bwipp/postscriptbarcode/wiki/Code-128

Data-Matrix BWIPP 规则

https://github.com/bwipp/postscriptbarcode/wiki/Data-Matrix

条码的Options 参考

https://github.com/bwipp/postscriptbarcode/wiki/Options-Reference


转载:https://blog.csdn.net/qq_33230723/article/details/102586553
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场