Barby

Barcodes for Ruby

Code 128 B

The following barcode symbologies are currently supported:

Writing your own barcode class

If you want to add support for a symbology that isn't currently supported, that's pretty easy. The only requirement is that your class has an encoding method which returns a string representation of the encoded barcode. It should also inherit the Barcode1D class. As an example, this EAN-8 barcode,

EAN-8 barcode

is represented by the string "1010111011010111100110010010011010101011100101110010011101000100101".

In the string, "black" or "bar" is represented with a 1 and "white" or "space" is represented by 0. One digit is one "X dimension" in length. So, a thick black line is represented by several 1s together. The image above was created with the outputter's :xdim option set to 2, i.e. 2 pixels, so the thinnest line possible is 2px wide.

This string is what the outputter classes use as input when generating images etc for a barcode.

2D barcodes

2D barcodes are similar to 1D barcodes with the only difference that their encoding method should return an array of strings instead of a single string. 2D barcodes are thus considered to be several 1D barcodes layered on top of each other. As an example, this QR Code,

QR Code barcode

is represented by this array of strings:

["111111100100101111111", "100000101001001000001", "101110100100001011101",
"101110101001001011101", "101110100011101011101", "100000101110101000001",
"111111101010101111111", "000000000011100000000", "111110111100110101010",
"011011010110110110111", "100101101001011000010", "110100000000010001110",
"100011111001001110010", "000000001101100111100", "111111101110110001110",
"100000100101110011101", "101110101010101111001", "101110101100111110100",
"101110101011000001000", "100000101000000101100", "111111101101000110010"]