Jump to content

PEAR Image_Barcode [error]


dotkpay

Recommended Posts

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');
?>

Link to comment
https://forums.phpfreaks.com/topic/260144-pear-image_barcode-error/
Share on other sites

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');
?>

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);
?>

 

 

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).
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.