Skip to content

dlenski/aztec_code_generator

 
 

Repository files navigation

Aztec Code generator

PyPI License: MIT Build Status

This is a pure-Python library to generate Aztec Code 2D barcodes.

Changelog

  • v0.1-v0.2: initial Python packaging
  • v0.3: allow optional border, more efficient matrix representation
  • v0.4: merge delimitry#5 and fix tests
  • v0.5:
    • code simplification
    • more efficient internal data structures (Enum)
    • encoding of FLG(n)
    • correct handling of Python 3 str vs. bytes (Aztec Code natively encodes bytes, not characters, and a reader's default interpretation of those bytes should be ISO-8859-1 aka Latin-1)
  • v0.6:
    • more code simplification
    • make Pillow dependency optional
    • add print_fancy for UTF-8 output (inspired by qrencode -t ansiutf8)
    • bugfix for DIGITPUNCT transition (and add missed test case)
    • allow customization of error correction percentage level
  • v0.7:
  • v0.8-v0.9:
    • replace Travis-CI with Github Actions for CI
  • v0.10
    • bugfix for lowercase → uppercase transition (fixes encoding of strings like abcABC)
  • v0.11
    • fix docstrings
    • change default module_size in image output to 2 pixels; ZXing can't read with module_size=1

Installation

Releases from PyPi may be installed with pip3 install aztec_code_generator.

Bleeding-edge version from master branch of this repository can be installed with pip3 install https://github.com/dlenski/aztec_code_generator/archive/master.zip.

Dependencies

Pillow (Python image generation library) is required if you want to generate image objects and files.

Usage

Creating and encoding

from aztec_code_generator import AztecCode
data = 'Aztec Code 2D :)'
aztec_code = AztecCode(data)

The AztecCode() constructor takes additional, optional arguments:

  • size and compact: to set a specific symbol size (e.g. 19, True for a compact 19×19 symbol); see keys(aztec_code_generator.configs) for possible values
  • ec_percent for error correction percentage (default is the recommended 23), plus size a

Saving an image file

aztec_code.save('aztec_code.png', module_size=4, border=1) will save an image file aztec_code.png of the symbol, with 4×4 blocks of white/black pixels in the output, and with a 1-block border.

Aztec Code

Creating an image object

aztec_code.image() will yield a monochrome-mode PIL Image object representing the image in-memory. It also accepts optional module_size and border.

Text-based output

aztec_code.print_fancy() will print the resulting Aztec Code to standard output using Unicode half-height block elements encoded with UTF-8 and ANSI color escapes. It accepts optional border.

aztec_code.print_out() will print out the resulting Aztec Code to standard output as plain ASCII text, using # and characters:

##  # ## ####
 #   ## #####  ###
 #  ##  # #   # ###
## #  #    ## ##
    ## # #    # #
## ############ # #
 ### #       ###  #
##   # ##### # ## #
 #   # #   # ##
 # # # # # # ###
    ## #   # ## ##
#### # ##### ## #
  # ##       ## ##
 ##  ########### #
  ##    # ##   ## #
     ## # ### #  ##
      ############
##   #     # ##   #
##  #    ## ###   #

Authors:

Originally written by Dmitry Alimov (delimtry).

Updates, bug fixes, Python 3-ification, and careful bytes-vs.-str handling by Daniel Lenski (dlenski).

License:

Released under The MIT License.

About

Aztec code generator in Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%