The Lua language

LuaBarcode

Generating Interleaved 2 of 5 barcodes

what is · introduction · functions · download · Português


Contents


What is LuaBarcode?

LuaBarcode is a Lua extension library that can be used to generate Interleaved 2 of 5 barcodes. These barcodes can be used for many purposes, like cataloguing products on a supermarket or helping automate bank invoice payments for example.

It can be used by any Lua application willing to generate this specific type of barcodes. The code has been tested and is know to run well both on Windows and on Unix platforms.

The library is available under the same terms as the Lua language, that is, it can be used at no cost for both academic and commercial purposes. And you thought you would never find a free barcode generator, heh? ;)

Copyright © 2000 ThieMari, PUC-Rio. All rights reserved.
Authors: Thiago Conde, Mariana Rego Monteiro
Contact: barcode@tcs.eng.br
Thanks to Roberto Ierusalimschy for helping us with the development of this library.

Initializing the library

To have the library functions made available to a Lua script, you can either download the Lua interpreter we provide which already has the library included in it, or you can initialize the library on your own Lua interpreter. To do that, the interpreter running the script must be linked to the luaBarcode library. The functions are registered in the Lua state given as the parameter to the function lua_barcodelibopen, the only C function exported by the library. The Lua scripts can then use all registered functions.

See some examples.

Download

The library can be downloaded in source code from the following links:

NEW!
LuaBarcode source for Lua 5.0:
luabarcode5.tar.gz (8 kb)
Kindly provided by Luis Henrique de Figueiredo.

LuaBarcode library (source code):
barcodelib.tar.gz (15 kb)
barcodelib.zip (15 kb)

The Lua interpreter with LuaBarcode library (source code):
luabarcodesrc.tar.gz (not available yet, my unix machine died last week)
luabarcode.zip (112 kb)

Lua interpreter with LuaBarcode (pre-compiled binaries):
luabarcode-static.tar.gz (n/a yet)
luabarcode-static.zip (windows - 155 kb)

Help compiling

LuaBarcode requires the GD library version 1.8.3 or superior, which can be downloaded from http://www.boutell.com/gd/.  Compiling GD is pretty straightforward and you shouldn't have any trouble.  The bad news is GD requires libpng, libjpeg and zlib, which could start getting to your nerves if you don't have any of them.  But for your convinience we have gathered all you need here:

gd-1.8.3.tar.gz (274 kb)
libpng-1.0.8.tar.gz (484 kb)
jpegsrc.v6b.tar.gz (613 kb)
zlib-1.1.3.tar.gz (168 kb)

Start by compiling zlib, then libpng and libjpeg.  GD should be the last one, since it depends on the other three.  Compiling the libraries in Unix is pretty easy, and a simple make should give you what you need.  On the other hand, compiling on Windows can be a little tricky if you don't have much experience.  Libjpeg is specially troublesome to compile, and if you have Visual Studio I recommend using nmake, as a makefile.vc is supplied and it makes your job much easier.  If you got really confused about all this or if you are just plain lazy, why don't you just get the pre-compiled Lua interpreter with LuaBarcode?  It's right up there on the Download section.

Function Reference

The functions of the API are described below.

barcode("number")

Creates the image with the number provided by the user. In case of success returns the image created. In case of error, the function returns nil followed by a string describing the error.  As the I2of5 specification states, the number to be encoded must have an even number of digits.  If you supply a string with an odd number of digits, a 0 will be appended to the string.
Example:

mybarcode = barcode("0123456789")

savebarcode(barcode, "format", "filename")

Gets the image created by the barcode function and saves it to the disk with the format and filename specified. The format can be either "jpeg" or "png", defaulting to png; gif images can't be generated because we would have to pay royalties to Unisys. In case of success the function returns a string which contains "OK". In case of error, the function returns nil followed by a string describing the error. After calling savebarcode() your object containing the image will no longer be available, because the function frees the resources used by the object.  If you create a barcode object and never pass it to savebarcode() the resources taken will not be released until your program finishes.
Example:

mybarcode = barcode("0123456789")
savebarcode(mybarcode, "png", "code.png")

readbarcode("filename", "format")

Reads a file containing a barcode image generated by the savebarcode() function and returns the string of digits encoded in it.  In case of error the function returns nil followed by the error description.  This function should receive some improvement soon, as it currently only decodes very simple barcodes: the barcodes on top of a single color background.
Example:

mybarcode = barcode("0123456789")
savebarcode(mybarcode, "png", "code.png")
mydigits = readbarcode("code.png", "png")

what is · introduction · functions · download · português