生成的条形码无法读取

时间:2015-03-03 22:37:05

标签: php barcode ean-13

我使用以下代码创建EAN13条形码。条形码创建没有任何问题,但是当我扫描它时,它无法识别。

有什么问题?

include('php-barcode.php');

$font     = 'fonts/GSMT.TTF';

$fontSize = 16;   // GD1 in px ; GD2 in point
$marge    = 10;   // between barcode and hri in pixel
$x        = 80;  // barcode center
$y        = 80;  // barcode center
$height   = 50;   // barcode height in 1D ; module size in 2
$width    = 2;    // barcode height in 1D ; not use in 2D
$angle    = 0;   

$code     = "111110001001"; // barcode, of course ;)
$type     = "ean13"; // 

$im     = imagecreatetruecolor(180, 180);
$black  = ImageColorAllocate($im,0x00,0x00,0x00);
$white  = ImageColorAllocate($im,0xff,0xff,0xff);
imagefilledrectangle($im, 0, 0, 180, 180, $white);

$data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);

if ( isset($font) ){
$box = imagettfbbox($fontSize, 0, $font, $data['hri']);
$len = $box[2] - $box[0];
Barcode::rotate(-$len / 2, ($data['height'] / 2) + $fontSize + $marge, $angle, $xt, $yt);
imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $black, $font, $data['hri']);
}

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);

0 个答案:

没有答案