background image

php 生成 EAN_13 标准的条形码

这连天看见有人法帖讨论如很用

PHP 生成条形码,所以就用了点时间学了学 EAN_13 标

.EAN_13 标准是广泛使用的条码编码标准,主要运用在商品流通方面,比如我们看到的商品

上的条码就是这种编码标准

,还有图书上的编码标准也是这种编码标准.

下面的就是我的一段代码生成的是

EAN_13 标准的条码,需要 php gd 环境

[code:1:dfc50fedcf]<?
function EAN_13($code) {
//一个单元的宽度
$lw = 2;
//条码高 
$hi = 100;
// the guide code is no coding,is used to show the left part coding type//
// Array guide is used to record the EAN_13 is left part coding type//
$Guide 

array(1=>'AAAAAA','AABABB','AABBAB','ABAABB','ABBAAB','ABBBAA','ABABAB','AB
ABBA','ABBABA');
$Lstart ='101';
$Lencode 

array("A" 

=> 

array('0001101','0011001','0010011','0111101','0100011','0110001','0101111','0111011','0110111','0
001011'),
"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 be 13 digits."); }
$lsum =0;
$rsum =0;
for($i=0;$i<(strlen($code)-1);$i )
{
if($i % 2)
{