Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save barcode in database

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

like image 346
user3651819 Avatar asked Dec 14 '25 03:12

user3651819


1 Answers

You can

  1. Save the actual code (string) in the database, and recreate the generation code on demand. This is the preferred method.
  2. You can save the image to your system and link to the image file with a location (path) in your database.
  3. You can save the image as a BLOB field in your database.
  4. You might be able to serialize the $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.

like image 86
Nanne Avatar answered Dec 16 '25 05:12

Nanne