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
Share on other sites

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.

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.