所以我使用http://barcode-coder.com/en/的 PHP 类来生成条形码。
我在我的网页上得到这个输出:
GIF87a,,¡üüþüü,,,þ„Ëí£œ´Ú+Þ¼û†"£Œæ‰‚Zʶî+–ðLkçz(ïþ~û ‡¿ñÈ "—Ì“± í(£ÔêäiÍB¦Ú.ëírÃä#¸\ £×º3»©~Ë_îù1nÏë÷[¾ÿ€HX˜fˆ˜˜5¨ØèHÃø(9iIy‰‰a™ÉÙé°éš *Z*IjššˆªÚÈê»+[+Gk›[†«Û«Åë,\ŒDlœüƒ¬ÜŒÃìý-]Bm‚ÝÍÁí^.^ÞgŽ™¾>ÍîžBþ/ßM_Ÿ}_¿Ýï¯À€É,fð`°„ {1l˜ë!ÄZ'ƪh±ÆþŒ©6r,åñc¨";‘,9 eÀ“*)±ly &¾—2Ѭ¹ ç»›:ñìù 躟Bý-:©¹£Jí0mzê<©ÞžREcõ*™¬Z½píú,?±Ò¾’¥bö,”´j™°m{nA¹ÆÞÒb÷®¼zuðíû°CÁºþ†aø°‹ÄŠ“4–Åøñ‰È’GP®¼ ³ªËš=pîü 4HÑ¢>“¶`ú4…Ôª3´æÄúõƒØ²Ð®½à6nݵyËöýxk᪉Ÿ6N¹hå ™wv®:Ô«[¿Ž=»öíÜ»{ÿ>¼øñäË›?oþªôÊë%·ü¾q|Åó×'|_p~Àûþûö×ûß]Ò5 \Âu`[ ªµàY ’õ X‚5aWju¡z¸¹´á$Rõ¡T!B5bS%*u"R)µ¢P-õbO1ê4#N5Öt£L9´cK=ªô#JA–4¤HE~t$GIf´¤EMNô$DQ64¥BUt%AY®ÔaL]:²¥?aî3æL_‚y¦Mi*Rf=mÊóæNkæ4§!qºs';yU§}úô'!{¦3(:….hP‰þqh9ŠóèT‹5)¥•&u©‘V•©¦æ±©=Ÿ:5ê¡jsj>¥Fµ*©ZóêX®kY³Òz+V¹î²ëV½†Që?¿z5¬Å†ue¬Á:³¬@É*ûì!Ñ3-µÕÂq-¶Ù.Ѭ2Ýεm\áŽKn¹æž‹nºê®Ën»î¾o¼òÎKo½öÞ‹o¾úîËo¿þþpÀLpÁŒp /ÌpÃ?qÄOLqÅ×S;
我什至无法弄清楚为什么会抛出这个问题。我从 dafont 获得了 Code 39 条形码,我只是使用了 php 类中包含的示例测试。我的实现是错误的还是需要额外的代码?
...Code
include('barcode.php');
Code...
然后
<?php
include('../../inc/php-barcode.php');
$font= '../../inc/3OF9_NEW.TTF';
// -------------------------------------------------- //
// PROPERTIES
// -------------------------------------------------- //
// download a ttf font here for example : http://www.dafont.com/fr/nottke.font
// - -
$fontSize = 10; // GD1 in px ; GD2 in point
$marge = 10; // between barcode and hri in pixel
$x = 125; // barcode center
$y = 125; // barcode center
$height = 50; // barcode height in 1D ; module size in 2D
$width = 2; // barcode height in 1D ; not use in 2D
$angle = 90; // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
$code = 'abcdef4'; // barcode, of course ;)
$type = 'Barcode39';
// -------------------------------------------------- //
// USEFUL
// -------------------------------------------------- //
function drawCross($im, $color, $x, $y){
imageline($im, $x - 10, $y, $x + 10, $y, $color);
imageline($im, $x, $y- 10, $x, $y + 10, $color);
}
// -------------------------------------------------- //
// ALLOCATE GD RESSOURCE
// -------------------------------------------------- //
$im = imagecreatetruecolor(300, 300);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
$white = ImageColorAllocate($im,0xff,0xff,0xff);
$red = ImageColorAllocate($im,0xff,0x00,0x00);
$blue = ImageColorAllocate($im,0x00,0x00,0xff);
imagefilledrectangle($im, 0, 0, 300, 300, $white);
// -------------------------------------------------- //
// BARCODE
// -------------------------------------------------- //
$data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);
// -------------------------------------------------- //
// HRI
// -------------------------------------------------- //
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, $blue, $font, $data['hri']);
}
// -------------------------------------------------- //
// MIDDLE AXE
// -------------------------------------------------- //
imageline($im, $x, 0, $x, 250, $red);
imageline($im, 0, $y, 250, $y, $red);
// -------------------------------------------------- //
// BARCODE BOUNDARIES
// -------------------------------------------------- //
for($i=1; $i<5; $i++){
drawCross($im, $blue, $data['p'.$i]['x'], $data['p'.$i]['y']);
}
// -------------------------------------------------- //
// GENERATE
// -------------------------------------------------- //
header('Content-type: image/gif');
imagegif($im);
imagedestroy($im);
?>