PHP 條碼產生器
相關網址
FOR PHP4
2.0.1下載點FOR PHP5
2.0.1下載點使用說明:
需準備的文件
class/font/Arial.ttf //此字型可以自己選定class/BCGColor.php
class/BCGBarcode.php
class/BCGDrawing.php
class/BCGFont.php
class/BCGcode39.barcode.php //此值選擇自己所需的BarCode編碼
使用時只要帶GET參數到image.php就可以顯示BarCode了
例:
http://網址/image.php?code=code39&o=1&t=40&r=1&text=ABCD&f1=Arial.ttf&f2=8&a1=&a2=&a3=相關參數說明如下
code=code39 (編碼方式)//如果有多重編碼需求再帶這個值
o=1 (1:PNG; 2:JPG; 3:GIF;)
t=40 (條碼高度)
r=1 (條碼粗細)
text=ABCD (條碼文字)
f1=Arial.ttf (使用字型)
f2=8 (字型大小)
a1=
a2=
a3=
o=1 (1:PNG; 2:JPG; 3:GIF;)
t=40 (條碼高度)
r=1 (條碼粗細)
text=ABCD (條碼文字)
f1=Arial.ttf (使用字型)
f2=8 (字型大小)
a1=
a2=
a3=
程式碼我用html/image.php這個檔修改如下
<?php
if(isset($_GET['code']) && isset($_GET['t']) && isset($_GET['r']) && isset($_GET['text']) && isset($_GET['f1']) && isset($_GET['f2']) && isset($_GET['o']) && isset($_GET['a1']) && isset($_GET['a2'])) {
require('class/BCGColor.php');
require('class/BCGBarcode.php');
require('class/BCGDrawing.php');
require('class/BCGFont.php');
if(include('class/BCGcode39.barcode.php')) {
//if(include('class/BCG' . $_GET['code'] . '.barcode.php')) {
if($_GET['f1'] !== '0' && $_GET['f1'] !== '-1' && intval($_GET['f2']) >= 1){
$font = new BCGFont('class/font/'.$_GET['f1'], intval($_GET['f2']));
} else {
$font = 0;
}
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$codebar = 'BCG'.$_GET['code'];
$code_generated = new $codebar();
if(isset($_GET['a1']) && intval($_GET['a1']) === 1) {
$code_generated->setChecksum(true);
}
if(isset($_GET['a2']) && !empty($_GET['a2'])) {
$code_generated->setStart($_GET['a2']);
}
if(isset($_GET['a3']) && !empty($_GET['a3'])) {
$code_generated->setLabel($_GET['a3']);
}
$code_generated->setThickness($_GET['t']);
$code_generated->setScale($_GET['r']);
$code_generated->setBackgroundColor($color_white);
$code_generated->setForegroundColor($color_black);
$code_generated->setFont($font);
$code_generated->parse($_GET['text']);
$drawing = new BCGDrawing('', $color_white);
$drawing->setBarcode($code_generated);
$drawing->draw();
if(intval($_GET['o']) === 1) {
header('Content-Type: image/png');
} elseif(intval($_GET['o']) === 2) {
header('Content-Type: image/jpeg');
} elseif(intval($_GET['o']) === 3) {
header('Content-Type: image/gif');
}
$drawing->finish(intval($_GET['o']));
}
else{
header('Content-Type: image/png');
readfile('error.png');
}
}
else{
header('Content-Type: image/png');
readfile('error.png');
}
?>
沒有留言:
張貼留言