php產生條碼代碼_PHP教程

來源:互聯網
上載者:User
php產生條碼代碼成條碼就是必鬚生成圖片了,在php產生圖片我們就必須用到gd庫來實現了,所以你得找到你的將php.ini檔案找到extension=php_gd2.dll 去掉前面的;。你就可能使用些執行個體了。

php教程產生條碼代碼
/*
產生條碼就是必鬚生成圖片了,在php產生圖片我們就必須用到gd庫來實現了,所以你得找到你的將php.ini檔案找到extension=php_gd2.dll 去掉前面的;
。你就可能使用些執行個體了。
*/

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($count1=9;$count1>=0;$count1--){
for($count2=9;$count2>=0;$count2--){
$count = ($count1 * 10) + $count2 ;
$text = "" ;
for($i=1;$i<6;$i++){
$text .= substr($this->cd_barras[$count1],($i-1),1) . substr($this->cd_barras[$count2],($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") {
$f1 = $thin ;
}else{
$f1 = $wide ;
}


imagefilledrectangle($img, $pos,1,$pos-1+$f1,53,$cl_black) ;
$pos = $pos + $f1 ;

if (substr($f,$i,1) == "0") {
$f2 = $thin ;
}else{
$f2 = $wide ;
}

imagefilledrectangle($img, $pos,1,$pos-1+$f2,53,$cl_white) ;
$pos = $pos + $f2 ;
}
}


imagefilledrectangle($img, $pos,1,$pos-1+$wide,53,$cl_black);
$pos=$pos+$wide;

imagefilledrectangle($img, $pos,1,$pos-1+$thin,53,$cl_white);
$pos=$pos+$thin;


imagefilledrectangle($img, $pos,1,$pos-1+$thin,53,$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);
}
}

?>

//調用 方法

include("codes.php");
$new_code = new cd_barra("1234567890","a.gif",1);

?>

http://www.bkjia.com/PHPjc/633039.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633039.htmlTechArticlephp產生條碼代碼成條碼就是必鬚生成圖片了,在php產生圖片我們就必須用到gd庫來實現了,所以你得找到你的將php.ini檔案找到extension=...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.