PHP Class : barcode
Version : 2.0.3
Licence : GPL / Cecill
Date : 2013-01-06
Author: DEMONTE Jean-Baptiste, HOUREZ Jonathan
Download the class PHP Barcode 2.0.3
Barcode PHP Class installation
Like all class, juste include the source file.
include('Barcode.php');
These classes are included :
- Barcode
- BarcodeI25
- BarcodeEAN
- BarcodeMSI
- Barcode11
- Barcode39
- Barcode93
- Barcode128
- BarcodeCodabar
- BarcodeDatamatrix
Barcode PHP Class utilisation
To use this class, tow statics functions are available, one for GD ressource and second one for FPDF
Barcode::gd($res, $color, $x, $y, $angle, $type, $datas, $width = null, $height = null); Barcode::fpdf($res, $color, $x, $y, $angle, $type, $datas, $width = null, $height = null);
$res
ressource gd or fpdf
Unit depends on ressource : pixel for GD and defined in the constructor for fpdf
$color
int, string
Descriptor of the color (int) for GD and hexadecimal string for fpdf (ie: "FF0000")
$x, $y
numeric
coordinate of barcode center
$angle
numeric
Rotation angle in degree
$datas
string
Value barcode (dependent on the type of barcode)
If barcode type include it, the presence of the checksum is not mandatory, it ise automatically recalculated
array
type : ean8, ean13, code11, code39, code128, codabar | |
---|---|
member | Type |
code | string |
type : std25, int25, code93 | |
---|---|
member | Type |
code | string |
crc | boolean |
type : msi | ||
---|---|---|
member | Type | |
code | string | |
crc | boolean | |
array | crc1 : string("mod10", "mod11") | |
crc2 : string("mod10", "mod11") |
type : datamatrix | |
---|---|
member | Type |
code | string |
rect | boolean (default : false) |
type (string)
- codabar
- code11 (code 11)
- code39 (code 39)
- code93 (code 93)
- code128 (code 128)
- ean8 (ean 8)
- ean13 (ean 13)
- std25 (standard 2 of 5 - industrial 2 of 5)
- int25 (interleaved 2 of 5)
- msi
- datamatrix (ASCII + extended)
$width, $height
numeric
width and height of an element, for 2D barcode (datamatrix), $height is not used
<< Returned value >>
Both methods return an array containing the dimensions of the barcode and the coordinates of its ends
array( 'width' => w, 'height'=> h, 'p1' => array('x' => x, 'y' => y), 'p2' => array('x' => x, 'y' => y), 'p3' => array('x' => x, 'y' => y), 'p4' => array('x' => x, 'y' => y) );
Example :
$im = imagecreatetruecolor(300, 300); $black = ImageColorAllocate($im,0x00,0x00,0x00); $white = ImageColorAllocate($im,0xff,0xff,0xff); imagefilledrectangle($im, 0, 0, 300, 300, $white); $data = Barcode::gd($im, $black, 150, 150, 0, "code128", "12345678", 2, 50);
"rotate" function allow to calculate coordinate of rotated point, usefull to center the "hri" (human readable interpretation)
Example
$box = imagettfbbox($fontSize, 0, $font, $data['hri']); $len = $box[2] - $box[0]; Barcode::rotate(-$len / 2, ($data['height'] / 2) + $fontSize + $marge, $angle, $xt, $yt); imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $blue, $font, $data['hri']);