I was wondering if I could save bar code in database. I am using "Code 39" type of barcode. Barcode will be generated from variable. I wanted to save it to database if possible. I have downloaded library from "http://www.barcodebakery.com". Can anyone give me suggestion how to do so?
Code works fine it displays the image, later on I will use bar code scanner to look for products, each of them will contain bar code.
<?php
require_once('class/BCGFontFile.php');
require_once('class/BCGColor.php');
require_once('class/BCGDrawing.php');
require('class/BCGcode39.barcode.php');
$font = new BCGFontFile('font/Arial.ttf', 18);
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$barcode="3RC402A00";
// Barcode Part
$code = new BCGcode39();
$code->setScale(2);
$code->setThickness(30);
$code->setForegroundColor($color_black);
$code->setBackgroundColor($color_white);
$code->setFont($font);
$code->parse($barcode);
// Drawing Part
$drawing = new BCGDrawing('', $color_white);
$drawing->setBarcode($code);
$drawing->draw();
header('Content-Type: image/png');
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>
Any suggestion is appreciated. Thanks
$drawing = new BCGDrawing('yourfilename.png', $color_white);
That would save the image to a file.
To save a file into database, refer to this stackoverflow post.
How can I store and retrieve images from a MySQL database using PHP?
You can
$drawing
object, and recreate this afterwards. Don't do this.So bottomline: save your string to the database, but if you really can't recreate the code on demand: save the image and link to that.