PHP Generate EAN_13 Standard Barcode Instance _php tutorial

Source: Internet
Author: User
The following is the PHP method for generating ean_13 standard barcodes, which requires a PHP+GD environment
Copy CodeThe code is as follows: function Ean_13 ($code) {
The width of a unit
$LW = 2;
High barcode
$hi = 100;
The guide code was no coding,is used to show the left part coding type//
Array Guide was used to record the ean_13 was left part coding type//
$Guide = Array (1=> ' aaaaaa ', ' aababb ', ' aabbab ', ' ABAABB ', ' Abbaab ', ' Abbbaa ', ' ababab ', ' Ababba ', ' Abbaba ');
$Lstart = ' 101 ';
$Lencode = Array ("A" = = Array (' 0001101 ', ' 0011001 ', ' 0010011 ', ' 0111101 ', ' 0100011 ', ' 0110001 ', ' 0101111 ', ' 0111011 ', ' 0110111 ', ' 0001011 '),
"B" = = Array (' 0100111 ', ' 0110011 ', ' 0011011 ', ' 0100001 ', ' 0011101 ', ' 0111001 ', ' 0000101 ', ' 0010001 ', ' 0001001 ', ' 0010111 '));
$Rencode = Array (' 1110010 ', ' 1100110 ', ' 1101100 ', ' 1000010 ', ' 1011100 ',
' 1001110 ', ' 1010000 ', ' 1000100 ', ' 1001000 ', ' 1110100 ');

$center = ' 01010 ';

$ends = ' 101 ';
if (strlen ($code)! = 13)
{die ("upc-a must is digits.");
$lsum = 0;
$rsum = 0;
for ($i =0; $i < (strlen ($code)-1); $i + +)
{
if ($i% 2)
{
$odd + = $ncode [$x]
$lsum + = (int) $code [$i];
}else{
$rsum + = (int) $code [$i];
}

}
$tsum = $lsum + $rsum;
if ($code [in]! = (10-($tsum% 10))
{
Die ("The Code is bad!");
}

echo $Guide [$code [0]];
$barcode = $Lstart;
for ($i =1; $i <=6; $i + +)
{
$barcode. = $Lencode [$Guide [$code [0]][($i-1)] [$code [$i]];
}
$barcode. = $center;

for ($i =7; $i <13; $i + +)
{
$barcode. = $Rencode [$code [($i)]];
}
$barcode. = $ends;

$img = Imagecreate ($lw *95+60, $hi +30);
$FG = imagecolorallocate ($img, 0, 0, 0);
$BG = Imagecolorallocate ($img, 255, 255, 255);
Imagefilledrectangle ($img, 0, 0, $lw *95+60, $hi +30, $BG);
$shift = 10;
for ($x =0; $x
if ($x <4) | | ($x >=45 && $x <50) | | ($x >=92))
{
$sh = 10;
} else {
$sh = 0;
}
if ($barcode [$x] = = ' 1 ')
{
$color = $FG;
} else {
$color = $BG;
}
Imagefilledrectangle ($img, ($x * $lw) +30,5, ($x + 1) * $LW +29, $hi +5+ $sh, $color);
}
/* Add the Human readable Label */
Imagestring ($img, 5,20, $hi +5, $code [0], $FG);
for ($x =0; $x <6; $x + +) {
Imagestring ($img, 5, $LW * (8+ $x *6) +30, $hi +5, $code [$x +1], $FG);
Imagestring ($img, 5, $LW * (53+ $x *6) +30, $hi +5, $code [$x +7], $FG);
}
Imagestring ($img, 4, $LW *95+17, $hi -5, $code [n], $FG);
/* Output the Header and Content. */
Header ("Content-type:image/png");
Imagepng ($IMG);

}

Ean_13 (' 6901028055048 ');

?>

http://www.bkjia.com/PHPjc/825189.html www.bkjia.com true http://www.bkjia.com/PHPjc/825189.html techarticle The following is the generation of EAN_13 standard bar code PHP method, need to PHP+GD environment copy code is as follows:? function Ean_13 ($code) {//width of a unit $LW = 2;//bar code High $hi = ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.