溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

php怎么生成EAN_13標(biāo)準(zhǔn)條形碼

發(fā)布時(shí)間:2021-07-24 14:01:14 來(lái)源:億速云 閱讀:142 作者:chen 欄目:開發(fā)技術(shù)

這篇文章主要介紹“php怎么生成EAN_13標(biāo)準(zhǔn)條形碼”,在日常操作中,相信很多人在php怎么生成EAN_13標(biāo)準(zhǔn)條形碼問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”php怎么生成EAN_13標(biāo)準(zhǔn)條形碼”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

下面的就是生成EAN_13標(biāo)準(zhǔn)的條碼的PHP方法,需要php+gd 環(huán)境 
  

復(fù)制代碼 代碼如下:

<?
function EAN_13($code) {
  //一個(gè)單元的寬度
  $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');

?> 

到此,關(guān)于“php怎么生成EAN_13標(biāo)準(zhǔn)條形碼”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI