dotkpay Posted April 1, 2012 Share Posted April 1, 2012 Hello, I have been trying to get my script to draw a barcode but it always outputs a message saying "the image cannot be displayed because it contains errors". I have googled the problem and it seems to be about the headers, I also made sure the "extension=php_gd2.dll" is not commented in php.ini. Could anyone please let me know why this script from pear.php.net can't draw a barcode on my xampp 1.7.7 with php 5.3.8 <?php require_once("Image/Barcode.php"); header("Content-type: image/png"); Image_Barcode::draw('1234', 'Code39', 'png'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/ Share on other sites More sharing options...
jcbones Posted April 1, 2012 Share Posted April 1, 2012 It is possible that your are throwing errors/notices in the script, thereby causing errors in the image. You will have to de-bug the image script, start by commenting the header, and see if there are errors/notices. Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333353 Share on other sites More sharing options...
dotkpay Posted April 1, 2012 Author Share Posted April 1, 2012 The script is processed exactly the way I posted it in this topic, I can't get it to work even when I comment the header line. I was wondering if it worked when you run it on your local server, @Jcbones Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333379 Share on other sites More sharing options...
jcbones Posted April 1, 2012 Share Posted April 1, 2012 OK, So I installed the barcode script (did you note that Barcode2 is out?), and am receiving the same errors as yourself. I did notice that you do not need the header, as that is handled inside the class. So, I did some deeper digging, and it seems that there are quite a few notices thrown in this script. So, I'm going to do something I do not believe I have ever done before. I suggest turning error reporting OFF. Run this script, and see what it gives you. <?php error_reporting(0); ini_set('display_errors',0); require_once('Image/Barcode.php'); Image_Barcode::draw('1234','Code39', 'png'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333397 Share on other sites More sharing options...
dotkpay Posted April 2, 2012 Author Share Posted April 2, 2012 Thanks Jcbones, Ican see the barcode now. And does error_reporting(0) turn off the errors for just the script or... Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333458 Share on other sites More sharing options...
jcbones Posted April 2, 2012 Share Posted April 2, 2012 Yes, just the one script. It is a runtime setting. Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333506 Share on other sites More sharing options...
dotkpay Posted April 2, 2012 Author Share Posted April 2, 2012 Unfortunately the above script can't display the encoded text below the barcode, I run into similar code at http://www.techrepublic.com/article/add-barcodes-to-your-web-apps-using-pear-and-php/5692389 but looks like it needs configuring just like the one I first posted cause it displays only errors. Someone please tell me what's wrong... <?php require_once("Image/Barcode/Code39.php"); $code = 56364357543745; $bc = new Image_Barcode_Code39('',2,4); $bc->draw($code, 'png', true, 120); ?> Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333530 Share on other sites More sharing options...
jcbones Posted April 3, 2012 Share Posted April 3, 2012 Worked for me. <?php //turn off errors, due to PEAR programmers =P error_reporting(0); ini_set('display_errors',0); require_once("Image/Barcode/Code39.php"); //require 3 in 9 file. $code = 56364357543745; //set the code. $bc = new Image_Barcode_Code39('',2,4); //start our class. header('Content-type: image/png'); //tell the page we want to display a PNG image. (handled automatically through the wrapper class, not directly to 3 in 9 though). imagepng($bc->draw($code, 'png', true, 120)); //draw the barcode, as a PNG file, turning off the text, setting the height at 120px. (use imagepng to create image, handled in the wrapper class, but not directly). ?> Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333810 Share on other sites More sharing options...
dotkpay Posted April 3, 2012 Author Share Posted April 3, 2012 Thanks Jcbones, you saw this thread through all by yourself. 3 days of barcoding... Quote Link to comment https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/#findComment-1333828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.