简体   繁体   English

将条形码保存在数据库中

[英]Save barcode in database

I was wondering if I could save bar code in database. 我想知道我是否可以在数据库中保存条形码。 I am using "Code 39" type of barcode. 我正在使用“Code 39”类型的条形码。 Barcode will be generated from variable. 条形码将从变量生成。 I wanted to save it to database if possible. 如果可能的话,我想将它保存到数据库中。 I have downloaded library from " http://www.barcodebakery.com ". 我从“ 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 谢谢

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. 您可以将图像另存为数据库中的BLOB字段。
  4. You might be able to serialize the $drawing object, and recreate this afterwards. 您可以序列化$drawing对象,然后重新创建它。 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. 所以底线:将您的字符串保存到数据库,但如果您真的无法按需重新创建代码:保存图像并链接到该数据库。

$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. 要将文件保存到数据库,请参阅此stackoverflow帖子。

How can I store and retrieve images from a MySQL database using PHP? 如何使用PHP从MySQL数据库存储和检索图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM