国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

用php生成EAN_13標準的條形碼

2024-05-04 22:53:35
字體:
來源:轉載
供稿:網友

這連天看見有人法帖討論如很用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','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 be 13 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*3 + $rsum;
    if($code[12] != (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<strlen($barcode);$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[12],$fg);
  /* output the header and content. */
  header("content-type: image/png");
  imagepng($img);
   
}

ean_13('6901028055048');

?> 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延吉市| 商都县| 和龙市| 高邑县| 府谷县| 于田县| 灵台县| 余姚市| 崇仁县| 读书| 绥阳县| 故城县| 瑞金市| 东兰县| 治多县| 元谋县| 惠水县| 祁阳县| 石门县| 和林格尔县| 丽江市| 廉江市| 荆门市| 浦江县| 双鸭山市| 南昌县| 灵丘县| 仪征市| 武穴市| 丹阳市| 锡林浩特市| 黔江区| 横峰县| 五常市| 阳城县| 通山县| 上林县| 旬邑县| 西乌珠穆沁旗| 泾川县| 邵阳县|