<- Back

barcode

Encode
Generate PNG from string
barcode -b '0123456789abcdABCD' -e code128 -g 400x225 -u pt -E | magick - -background white -alpha remove -alpha off out.png
-b
string to encode (use input file if missing)
-e
encoding type (default is best fit for first string)
-g
geometry on the page: [x][++]; Note that an additional white margin of 10 points is added to the printout.
-u
unit ("mm", "in", ...)
-E
print one code as eps file (default: multi-page ps)
Generate SVG from string svgo is optional to reduce the size of the generated image. Be careful though, it might break the output!
barcode -b 'andreas-mausch.de' -e code128 -g 400x225 -u pt -S | svgo - > out.svg
Generate with zint
zint --barcode=20 --data='0123456789abcdABCD' --scale=4 --output=out.png
--barcode
-b, Barcode type, see -t for all available types. Can also be a string like CODE128.
--data
-d, Data to encode
--scale
Increase size
--output
-o, Output file
--filetype
Will be detected automatically by the output file naming. Supported types are BMP, EMF, EPS, GIF, PCX, PNG, SVG, TIF, TXT.
Decode
via zbarimg
zbarimg code.png

Encoding types

Known encodings are (synonyms appear on the same line):
        "ean", "ean13", "ean-13", "ean8", "ean-8"
        "upc", "upc-a", "upc-e"
        "isbn"
        "39", "code39"
        "39ext", "code39ext"
        "128c", "code128c"
        "128b", "code128b"
        "128", "code128"
        "128raw"
        "i25", "interleaved 2 of 5"
        "cbr", "codabar"
        "msi"
        "pls", "plessey"
        "code93", "93"
        "code11", "11"

Code39 vs. Code128

Differences between Code128 A, B, C

  • 128A (Code Set A) – ASCII characters 00 to 95 (0–9, A–Z and control codes), special characters, and FNC 1–4
  • 128B (Code Set B) – ASCII characters 32 to 127 (0–9, A–Z, a–z), special characters, and FNC 1–4
  • 128C (Code Set C) – 00–99 (encodes two digits with a single code point) and FNC1 – https://en.wikipedia.org/wiki/Code_128#Subtypes

So if your string only contains digits, you can use Set C to save some space.

Error correction and checksum

Code128 does have a checksum character, while Code39 does not. However, neither has any type of error correction with redundant data, like in QR codes.