dpjuppr1361 2015-05-31 19:09
浏览 202

PHP Content-Type不显示条形码图像

I am trying to generate bar code using http://www.barcodebakery.com but my script is not displaying bar code image. Here is my code:

<?php 

require_once('../barcodegen/class/BCGFontFile.php');
require_once('../barcodegen/class/BCGColor.php');
require_once('../barcodegen/class/BCGDrawing.php');
require_once('../barcodegen/class/BCGcode128.barcode.php');


//$font = new BCGFontFile('./barcodegen/class/font/Arial.ttf', 18);
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);

// Barcode Part
$code = new BCGcode128();
$code->setScale(2);
$code->setThickness(30);
$code->setForegroundColor($color_black);
$code->setBackgroundColor($color_white);
//$code->setFont($font);
$code->setStart(NULL);
$code->setTilde(true);
$code->parse('123456');

// Drawing Part
$drawing = new BCGDrawing('', $color_white);
$drawing->setBarcode($code);
$drawing->draw();


header('Content-Type: image/png');

$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);

?>

Is there anything that I am missing? when I print $drawing I get value ‰PNG IHDRÊO%zÍ”LtEXtCopyrightGenerated with Barcode Generator for PHP http://www.barcodephp.comYp¸³IDATxœíØÑnƒ †QXöþ¯Ì.LQa¶ÝŸ.圫q2óµtZk¥”Zëþóf9Ïìö瞎ίx>«ŸÓ›¯áþÚæW¼sîÿæù ïßáùÌÑ çwr4çÑ¿ñëòð'äE¼’Aò"H^É‹ y$/‚äE¼’Aò"H^É‹ y$/‚äE¼’Aò"H^É‹ y$/‚äE¼’Aò"H^É‹ y$/‚äE¼’Aò"H^É‹ y$/‚äE¼’Aò"H^É‹ y$/‚äE¼’Aò"H^É‹ y$/‚äE¼ª­µw¯e÷"H^É‹ y$/‚äEÐ÷»ð¯ÕZK)ço7Ûø¦?Ú_ž¸»×С•Ãxkm«gŸÖ-ËgÕkóýi>rçÐ"V8Žg£íç~+Ú*‹çu( ÖZëcÛùeC{”‹·U÷Ú_’ž3ÚŸ¼{íì^/;©³µöÄvøaÖÍkô’þܹ\ZúáØ{½­m¯úuÚR–Þº_ú Fÿ3Ž*¼<ºò½Ý,iŽýb>ÌžúIEND®B‚`

but header('Content-Type: image/png') is not displaying any image but just a small icon.

  • 写回答

1条回答 默认 最新

  • dtcwehta624485 2015-06-01 08:46
    关注

    Your code should be working as it follows the examples from the User Guide.

    Why are you trying to print $drawing? Just open the page in your browser and you should see the generated Barcode. As they explain

    If you have specified a filename before, the image will be saved into this file, otherwise it will be displayed.

    So, if you want it to be saved somewhere, just add a filename when needed.

    $drawing = new BCGDrawing('/route/to/your/file.png', $colorBack);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的