PHP generated barcode code into a barcode is the need to generate images, in PHP generated images we have to use the GD library to achieve, so you have to find your php.ini file to find Extension=php_gd2.dll remove the front; You may have used some examples.
PHP Tutorial generates barcode code
/*
To generate a barcode is the need to generate pictures, in PHP generated images we have to use the GD library to achieve, so you have to find your php.ini file to find Extension=php_gd2.dll remove the front;
。 You may have used some examples.
*/
Class Cd_barra
{
var $file;
var $into;
var $cd _barras = Array (0=> "00110",1=> "10001",2=> "01001",3=> "11000",4=> "00101",
5=> "10100",6=> "01100",7=> "00011",8=> "10010",9=> "01010"
);
function Cd_barra ($value, $files, $into =1) {
$lower = 1; $hight = 55;
$this->into = $into;
for ($count 1=9; $count 1>=0; $count) {
for ($count 2=9; $count 2>=0; $count 2--) {
$count = ($count 1 *) + $count 2;
$text = "";
for ($i =1; $i <6; $i + +) {
$text. = substr ($this->cd_barras[$count 1], ($i-1), 1). substr ($this->cd_barras[$count 2], ($i-1), 1);
}
$this->cd_barras[$count] = $text;
}
}
$img = Imagecreate ($lower *95+300, $hight +30);
$img = Imagecreate (145,55);
$img = Imagecreate (395,73);
$CL _black = imagecolorallocate ($img, 0, 0, 0);
$CL _white = imagecolorallocate ($img, 255, 255, 255);
Imagefilledrectangle ($img, 0, 0, $lower *95+1000, $hight +30, $cl _white);
Imagefilledrectangle ($img, 1,1,1,53, $cl _black);
Imagefilledrectangle ($img, 2,1,2,53, $cl _white);
Imagefilledrectangle ($img, 3,1,3,53, $cl _black);
Imagefilledrectangle ($img, 4,1,4,53, $cl _white);
$thin = 1;
if (Substr_count (Strtoupper ($_server[' server_software '), "Win32")) {
o tamanho para windows tem que ser 3
For Windows, the wide bar has = 3
$wide = 3;
} else {
$wide = 2.72;
}
$pos = 5;
$text = $value;
if ((strlen ($text)% 2) <> 0) {
$text = "0". $text;
}
while (strlen ($text) > 0) {
$i = Round ($this->barra_left ($text, 2));
$text = $this->barra_right ($text, strlen ($text)-2);
$f = $this->cd_barras[$i];
for ($i =1; $i <11; $i +=2) {
if (substr ($f, ($i-1), 1) = = "0") {
$f 1 = $thin;
}else{
$f 1 = $wide;
}
Imagefilledrectangle ($img, $pos, 1, $pos -1+ $f 1,53, $cl _black);
$pos = $pos + $f 1;
if (substr ($f, $i, 1) = = "0") {
$f 2 = $thin;
}else{
$f 2 = $wide;
}
Imagefilledrectangle ($img, $pos, 1, $pos -1+ $f 2,53, $cl _white);
$pos = $pos + $f 2;
}
}
Imagefilledrectangle ($img, $pos, 1, $pos -1+ $wide, $cl _black);
$pos = $pos + $wide;
Imagefilledrectangle ($img, $pos, 1, $pos -1+ $thin, $cl _white);
$pos = $pos + $thin;
Imagefilledrectangle ($img, $pos, 1, $pos -1+ $thin, $cl _black);
$pos = $pos + $thin;
$this->put_img ($img, $files);
}
function Barra_left ($input, $comp) {
Return substr ($input, 0, $comp);
}
function Barra_right ($input, $comp) {
Return substr ($input, strlen ($input)-$comp, $comp);
}
function put_img ($image, $file) {
if ($this->into) {
Imagegif ($image, $file);
}
else {
Header ("Content-type:image/gif");
Imagegif ($image);
}
Imagedestroy ($image);
}
}
?>
Calling methods
Include ("codes.php");
$new _code = new Cd_barra ("1234567890", "A.gif", 1);
?>
http://www.bkjia.com/PHPjc/633039.html www.bkjia.com true http://www.bkjia.com/PHPjc/633039.html techarticle PHP generated barcode code into a barcode is the need to generate images, in PHP generated images we have to use the GD library to achieve, so you have to find your php.ini file to find extension= ...