Random Robo Smith
Published

Create Barcodes with Pure Python

In this blog we'll learn to creating barcode using python, here we'll be learning creating barcode in 3 different ways:

BeginnerProtip1 hour586
Create Barcodes with Pure Python

Things used in this project

Hardware components

SB Components Pico Barcode & QR Code Scanner HAT
×1

Story

Read more

Code

Code snippet #1

Plain text
>>> import barcode
>>> ean = barcode.get('ean13', '123456789102')
# Now we look if the checksum was added
>>> ean.get_fullcode()
'1234567891026'
>>> filename = ean.save('ean13')
>>> filename
'ean13.svg'
>>> options = dict(compress=True)
>>> filename = ean.save('ean13', options)
>>> filename
'ean13.svgz'

Code snippet #2

Plain text
>>> import barcode
>>> from barcode.writer import ImageWriter
>>> ean = barcode.get('ean13', '123456789102', writer=ImageWriter())
>>> filename = ean.save('ean13')
>>> filename
'ean13.png'

Code snippet #3

Plain text
$ python-barcode create "My Text" outfile
New barcode saved as outfile.svg.
$ python-barcode create -t png "My Text" outfile
New barcode saved as outfile.png.
$ python-barcode create -b ean8 -t jpeg "1234567" ean8_out
New barcode saved as ean8_out.jpg.

Credits

Random Robo Smith

Random Robo Smith

93 projects • 58 followers
Electronic Enthusiast I do Projects, Tutorials, Reviews and more...
Thanks to kamaluddin Khan.

Comments