Create bar code in php
<?php
function createBarcode() {
$height = 52;
$width = 102;
$lines = array();
$lines[0] = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
$lines[1] = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
$lines[2] = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
$lines[3] = "000000000000100011111001111000000100001110000111000010000001110000100000011100000010001111100000000000";
$lines[4] = "000000000000100010000000000100000100000001001000100010000010001000010000100010000010001000000000000000";
$lines[5] = "000000000000100001000000000100111110000001001000100010000010001000001000100010000010000100000000000000";
$lines[6] = "000000000000100000100000000100100100000001001000100010000010001000111100100010000010000010000000000000";
$lines[7] = "000000000000100000010000111000010100001110001111000001000001110001000100100010000010000001000000000000";
$lines[8] = "000000000010100000001000010000010000001000000100000000100010001001000100100010001010000000100000000000";
$lines[9] = "000000000001100010001000001000001000001000000010000000010010001001000100100010000110001000100000000000";
$lines[10] = "000000000000100001110001111100001000001111000001000111110001110000111000011100000010000111000000000000";
$lines[11] = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
$lines[12] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[13] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[14] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[15] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[16] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[17] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[18] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[19] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[20] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[21] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[22] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[23] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[24] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[25] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[26] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[27] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[28] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[29] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[30] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[31] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[32] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[33] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[34] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[35] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[36] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[37] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[38] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[39] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[40] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[41] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[42] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[43] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[44] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[45] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[46] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[47] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[48] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[49] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[50] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[51] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines[52] = "110100111001011001110010001011000111000101101100001010011011110110101100111001110101100011000111010110";
$lines2 = array();
$count = count($lines);
for( $i=0; $i< $count; $i++ )
$lines2[$i] = tstr($lines[$i]);
writeBarcode(getHeader($width, $height) . implode('', $lines2));
}
function tstr($data ) {
static $tStrCache;
if( isset( $tStrCache[$data] ))
return $tStrCache[$data];
$tchar = 0;
$total = "";
$tpos = 8;
for( $i = 0; $i < strlen($data); $i++ ) {
$tpos = $tpos - 1;
if( substr($data, $i, 1) !== '0' )
$tchar = $tchar + pow(2, $tpos);
if( $tpos == 0 ) {
$total = $total . chr($tchar);
$tpos = 8;
$tchar = 0;
}
}
if( $tpos != 8 ) {
$total = $total . chr($tchar);
}
$x = strlen($total) % 4;
if( $x == 0 )
$x = 4;
for( $i = $x; $i<=3; $i++ ) {
$total = $total . chr(0);
}
$tStrCache[$data] = $total;
return $total;
}
function size($length) {
$length = (double)$length;
if ( $length > 255 ) {
if( $length > 65535 )
$length = 65535;
return chr($length % 256) . chr(floor($length / 256));
} else {
return chr($length) . chr(0);
}
}
function getHeader($width, $height) {
return chr(66) . chr(77) . size(62 + ($width * $height)) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(62) . chr(0) . chr(0) . chr(0) . chr(40) . chr(0) . chr(0) . chr(0) . size($width) . chr(0) . chr(0) . size($height) . chr(0) . chr(0) . chr(1) . chr(0) . chr(1) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(37) . chr(14) . chr(0) . chr(0) . chr(37) . chr(14) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(255) . chr(255) . chr(255) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0);
}
function writeBarcode($data) {
header( "Content-Type: image/bmp" );
echo $data;
}
createBarcode();
Comments
Post a Comment