1

我使用以下代码创建 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);
4

0 回答 0