User Tools

Site Tools


python:barcode

Python Barcode

huBarcode

Setup huBarcode

  1. step1: download hubarcode from https://github.com/hudora/huBarcode
  2. step2: install python processing image:
    pip uninstall PIL
    pip install pillow
  3. step2: build and install hubarcode:
    python setup.py build
    python setup.py install

Example create Barcode with hubarcode

Create Firt example barcode.py and run it:

  1. Step1: Create barcode.py
    import sys
    from hubarcode.code128 import Code128Encoder
    if __name__ == '__main__':
        print 'barcode generator'
        encoder = Code128Encoder(sys.argv[1])
        encoder.save("test.png")
  2. Step2: Run it:
    python barcode.py 123

    Not run:

    barcode.py 123

    Because it generate error:

    ImportError: No module named Image

Custom options in Encoder

Below are default options for Code128Encoder:

self.options.get('show_label', True)
self.options.get('ttf_fontsize', default_fontsize)
self.options.get('ttf_font')
self.options.get('label_border', 0)
self.image_height = self.options.get('height') or (self.image_width / 3)
self.options.get('bottom_border', 0)

Create Custom options:

options['height'] = 25
options['ttf_fontsize'] = 8
options['bottom_border'] = 2
python/barcode.txt · Last modified: 2022/10/29 16:15 by 127.0.0.1