Patagonikus Posted November 15, 2010 Share Posted November 15, 2010 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 https://forums.phpfreaks.com/topic/218776-export-to-image-a-barcode-of-barcodegen-class/ Share on other sites More sharing options...
WTFranklin Posted November 16, 2010 Share Posted November 16, 2010 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 https://forums.phpfreaks.com/topic/218776-export-to-image-a-barcode-of-barcodegen-class/#findComment-1135138 Share on other sites More sharing options...
Patagonikus Posted November 17, 2010 Author Share Posted November 17, 2010 No, that does not work, I had already tried that way. My question was if I could make it faster to print the image by inserting it into a PDF. Now I'm going to print the image in the browser and then I'll rebuild it with TCPDF Thanks for the time Link to comment https://forums.phpfreaks.com/topic/218776-export-to-image-a-barcode-of-barcodegen-class/#findComment-1135479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.