% Code128 -- generate barcodes % Jessica L. Parsons % Tue Jan 15 14:56:13 PST 2008 #![Code 128](code128.png =264x70) ##Synopsis `code128` _barwidth_ _string_ `[>` _output-file_`]` ##Description **Code128** generates barcode images in JPG (or GIF, if you don't have a copy of `libjpeg` on your system) using [Boutell.com](http://www.boutell.com)'s [GD](http://www.boutell.com/gd/) graphics library. It takes two arguments -- the width of the smallest bar in the output (typically 1; the title image on this page uses 2) in pixels, and the string you wish to generate a barcode of. It encodes that string using the **Code 128** barcode format, and dumps the resulting image to standard out. There are approximately a million versions of **GD** out there, but if your version supports [PNG](https://www.w3.org/TR/PNG/) images, it will produce a png, otherwise if it supports [JPEG](http://www.ijg.org/)s, it will produce a jpeg, otherwise otherwise it will produce a [GIF](https://medium.com/matt-bors/world-war-g-8b90a02a4432). ##Bugs 1. **Code 128** format barcodes can get to be fairly long. A code 128 barcode is 11 _`barwidth`_ long per character, plus 55 barwidth for the message envelope. ##Source Code **Code128** uses my [configuration](/~orc/Code/configure) system to configure itself for building on various platforms. To build the code, untar the archive, run `configure.sh`, then run a `make`. =[version 0.5](code128-0.5.tar.bz2)= A fairly major rework on the internals of this code; first, I implemented CODEC (compresses number strings by up to ~50%), and secondly I took out all of the places where I was table scanning the code128[] array and replaced it with lookups into a 3 automatically generated maps (generated by the new program `mkcodes`, which is used to make the file `table.c` which contains `codeAmap[]`, `codeBmap[]`, and `controlmap[]` (codeC doesn't use lookups; the 100 CODEC points are 0..99 so no lookup is needed.)) =[version 0.4](code128-0.4.tar.bz2)= It turns out that when I originally wrote this code I'd completely misread the checksum generation algorithm, so instead of code128 barcodes I was generating orc128 barcodes. So, as part of a small software death march to updating the configuration to work with a more uptodate version of libgd (which was a pain because libgd has gone not only to GNU autoconfigure, but has -- at least on Unix -- abandoned make for cmake, so I couldn't even salvage a GNU Makefile.in but had to create one from scratch instead) I reworked the checksum computation so that it actually works. Other features in 0.4 include changing the [copyright](COPYRIGHT.html) to a 3-clause BSD-style one and changing the output format of the barcode image to (depending on libgd support) PNG, then Jpeg, and finally (the finally free-to-use) GIF format. =[version 0.2](code128-0.2.tar.gz)= The first release. It's version 0.2 because version 0.1 didn't include the [copyright notice](COPYRIGHT.html).