Jump to content

Export to image a barcode of barcodegen class


Patagonikus

Recommended Posts

Hello,

I use barcodegen.1d for php5 v2.2.0 to make barcodes, and works fine.

 

I can show OK in html page with this code:

<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

<?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:

<?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:

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

 

Bye! and thanks

Link to comment
Share on other sites

Hey,

I was just taking a look and you're passing image.php file to $originalFile as the file to get turned into a jpg instead of a .png. The error is getting sent because imagecreatefrompng is expecting a .png file so you'd need to pass the path to the png file generated from image.php. I hope that helps

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.