Python生成一维码

参考页面 https://pypi.org/project/python-barcode/

利用python-barcode的库

一、安装python-barcode库

#安装前提条件库
pip install Pillow
#安装
pip install python-barcode

二、用python-barcode库将文本转为barcode

目前支持的编码方式

  • EAN-8
  • EAN-13
  • EAN-14
  • UPC-A
  • JAN
  • ISBN-10
  • ISBN-13
  • ISSN
  • Code 39
  • Code 128
  • PZN
import barcode
from barcode.writer import ImageWriter
#支持的编码
"""
[u'code39', u'code128', u'ean', u'ean13', u'ean8', u'gs1', u'gtin',
 u'isbn', u'isbn10', u'isbn13', u'issn', u'jan', u'pzn', u'upc', u'upca']
"""
def barcode_to_png(barcode_type,text_str,filename):
    EAN = barcode.get_barcode_class(barcode_type)
    ean = EAN(text_str, writer=ImageWriter())
    ean.save(filename)

if __name__=="__main__":
    barcode_to_png('code128',"M13OSA100210012000",'文件位置')
原文地址:https://www.cnblogs.com/Evan-fanfan/p/10855157.html