sseeley Posted November 26, 2010 Share Posted November 26, 2010 Hi I am hoping somone can help me? I am trying to generate a simple barcode to use on a website which will print out a label. I have found barcodephp.com and have installed this. When I use their test facility below it works fine and generates a barcode for A123. <?php require('class/BCGFont.php'); require('class/BCGColor.php'); require('class/BCGDrawing.php'); require('class/BCGcode39.barcode.php'); $font = new BCGFont('./class/font/Arial.ttf', 18); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $code = new BCGcode39(); $code->setScale(2); $code->setThickness(30); $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->setChecksum(false); $code->parse('A123'); // Drawing Part $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); ?> As soon as I insert this same code into my code, or just try and put the barcode into a table (below) I get an error as shown. Can anyone point me in the right direction? echo "<table border = '1'>"; echo "<tr>"; echo "<td>"; require('class/BCGFont.php'); require('class/BCGColor.php'); require('class/BCGDrawing.php'); require('class/BCGcode39.barcode.php'); $font = new BCGFont('./class/font/Arial.ttf', 18); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $code = new BCGcode39(); $code->setScale(2); $code->setThickness(30); $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->setChecksum(false); $code->parse('A123'); // Drawing Part $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); echo "</td>"; echo "</tr>"; echo "</table>"; <table border = '1'>‰PNG IHDRœSådù{LtEXtCopyrightGenerated with Barcode Generator for PHP http://www.barcodephp.comYp¸JIDATxœíA(t_ÀÏ{MchM’4iÒ42Yiú‡,,$I–”,$IÒ°øB’…b!ÉÊ‚YL’&YJRJš˜$é%M’Æ,¦§ù/Nßëeæ½oø†ïÍéüVæÜsï¼ó~Þ½÷]@2™„ß‚ DðguŽV$óÖl}—Ö_»Î¯¦ÉdÌï¸3"0ä`©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©a©Ôÿ_Œ¡?©a©a©a©É©}}}‚ ‚prr’a—‰‰ A...Ò¶>??OLLTWWçççÖÕÕ---½¿¿HÛÚÚjjj***ÊËË«©©™™™y{{û«J~€d.Çm6^ðÀÀ@&]B¡Éd€óóóÔÖÛÛ[§Ó‰VUUy<Q µµ5‘H(i˜ãr¹¼^¯ÅbÁü‡‡‡¬Õö ä†Ô ¼ã`³Ùb±˜~~0,((@i¥¶´´@IIÉññ1FÎÎÎÊÊÊàׯ_ÙÜܫպ¿¿‘ûûûúúzèîîÎ^qÙ'7¤¢ÎµµµÚÚZX__×ÊŒÇã~¿;-©çççØ´¶¶¦Ž4}>ÌÍÍ©sÂá0˜L¦×××,—}r@j4ʼnôöövjj |>_ÚLI’***Àl6¯®®jI]YYÁ¦ûû{u<‹a\’¤d2999ÙÖÖvss£ÎI$˜syy™Õ*³IH]XX€ÚÚÚd2‰DðžF"‘ÔÌããcT‡“¿OÊR¥J’———?Ä_^^°Ë‘j ÿmaßFHõx<0;;‹qMÍ”$iggGù¨³¦¦%âšÞ+©9<<¬¬¬¿ßÿÉ"~£K=;;ûðôÌÍÍáʧuë>+Õëõ@ooojSGGNì&“ÉàF“Æ—::: õõõJD’$Üý¾Ÿ’Š«µÕjÅõ¸¨# ÊžÙ˜Zª,Ëøš±¸¸¨Žã¾´µµU¿{æR€(Š¢(¦ýE‘eY’¤D"‡ÛÛÛqMÅeÛ˜Zj(Q£Ñ¨:¾¼¼Œñ´O•B†R÷ööÌf3ÌÏÏÿñ’dYnll€®®®LJø'ZjOO袤%©{{{xN499™áUá~Jy5 Æ•úúúЧB¥¥¥ŽðÔÐápèŒðG©»»»ht||<µ5¦];OOOñUøEýÆ•º¾¾‹åéé)µu{{…B!ô¥*³îØØXjëÕÕÎð©Ç¼øÕN§ó3Õü(Æ•ÚÜܬ³tɲ\^^Z#èH=::Âi`ppP«»ÃáP¿+à™åÐÐPfuü*UyoÙÝÝÕÊñûý8 ~8íSÐ’úøøˆ›jŸÏ'Ë²Öø¸³X,Á`#±XÿnS\\|ww÷ù²~ƒJžžÆÕTç¦___£x]«–ÔÁÁAlr¹\ÿ¥C9èèïïÇL§ÓéõzV+ØíöƒƒƒlUúTªÛ퀑‘ý4üšÛíNÛª%Õn·ëoªÕ]@KK‹Íf3›Í.—kxxØÈÏ(ò?ãö#)‰6¡IEND®B`‚</table> Many thanks Stuart Link to comment https://forums.phpfreaks.com/topic/219900-barcode-generation/ Share on other sites More sharing options...
MrXHellboy Posted November 26, 2010 Share Posted November 26, 2010 As far as i know, header('Content-Type: image/png'); and HTML output wont go together...... Unless you want to do difficult stuff... But you have to use google for that.... This is not i know for sure, but i assume you can't use html output with content-type image/png Link to comment https://forums.phpfreaks.com/topic/219900-barcode-generation/#findComment-1139932 Share on other sites More sharing options...
JakeTheSnake3.0 Posted November 30, 2010 Share Posted November 30, 2010 From what I can see the script is meant to be placed elsewhere on your server to be accessed directly. It will generate an image file (like as if you were to access an image directly...http://mydomain.com/barcode.png). So essentially if you want the image to display, put an img tag in the HTML in which the src attribute points to the php script with a GET parameter set to the barcode #...like http://mydomain.com/generatebarcode.php?id=20339319394013 The php script generatebarcode.php holds the script you showed us, and it gets the barcode # from the "id" GET variable. The image should then show up on the page. Link to comment https://forums.phpfreaks.com/topic/219900-barcode-generation/#findComment-1141175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.