1

I use the following code to create an EAN13 barcode. The barcode is created without any issues, but when I scan it it is not recognized.

What is the problem?

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);
Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
nad
  • 1,068
  • 6
  • 16
  • You have not said anything about how you scan the barcode. Does the scanner accept other barcodes that use EAN13? – Kevin Panko Mar 03 '15 at 22:46
  • I saved the image generated and used an online scanner. (http://zxing.org/w/decode.jspx) I end up with an error message saying no barcode was found in this image. – nad Mar 03 '15 at 22:47

0 Answers0