Page 1 of 1

Export to image a barcode of barcodegen class

Posted: Mon Nov 15, 2010 2:59 pm
by Patagonikus
Hello,
I use barcodegen.1d for php5 v2.2.0 to make barcodes, and works fine. (http://www.barcodephp.com/download.php)

I can show OK in html page with this code:

Code: Select all

<img alt="" src="image.php"> <br> 
barcodegen creates a png image (image.php).

My question is: Exists a script to export the image "image.php" to "image.jpg" for example

image.php

Code: Select all

<?php

// Including all required classes

require('class/BCGFont.php');

require('class/BCGColor.php');

require('class/BCGDrawing.php'); 



// Including the barcode technology

include('class/BCGcode128.barcode.php'); 



// Loading Font

$font = new BCGFont('./class/font/Arial.ttf', 18);



// The arguments are R, G, B for color.

$color_black = new BCGColor(0, 0, 0);

$color_white = new BCGColor(255, 255, 255); 



$code = new BCGcode128();

$code->setScale(2); // Resolution

$code->setThickness(30); // Thickness

$code->setForegroundColor($color_black); // Color of bars

$code->setBackgroundColor($color_white); // Color of spaces

$code->setFont($font); // Font (or 0)

$code->parse('122222222-adm-a'); // Text





/* Here is the list of the arguments

1 - Filename (empty : display on screen)

2 - Background color */

$drawing = new BCGDrawing('', $color_white);

$drawing->setBarcode($code);

$drawing->draw();



// Header that says it is an image (remove it if you save the barcode to a file)

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



// Draw (or save) the image into PNG format.

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

?>

A basic convert script from png to jpg:

Code: Select all

<?php
// Quality is a number between 0 (best compression) and 100 (best quality)
function png2jpg($originalFile, $outputFile, $quality) {
    $image = imagecreatefrompng($originalFile);
    imagejpeg($image, $outputFile, $quality);
    imagedestroy($image);
}

png2jpg("image.php","image.jpg", 100);  //convert to jpg
?>
But this didn't work, I've the error:

Code: Select all

Warning: imagecreatefrompng(): 'prueba.php' is not a valid PNG file in /var/www/barcodegen.1d-php5.v2.2.0/convertir.php
Bye! and thanks