【发布时间】:2019-12-04 15:01:39
【问题描述】:
我想使用 php 将 Data-matrix 库生成 QR 码图像存储到 mysql 数据库中。我正在尝试使用 jpgraph 库。 请提供解决方案..
<?php
require_once('jpgraph/datamatrix/datamatrix.inc.php');
$data = '1234567890';
$shape = DMAT_AUTO;
$encoding = ENCODING_AUTO;
$modulewidth = 3;
$quietzone = 10;
$color1 = 'black';
$color0 = 'white';
$colorq = 'white';
$outputfile = '';
// Create and set parameters for the encoder
$encoder = DatamatrixFactory::Create($shape);
$encoder->SetEncoding($encoding);
// Create the image backend (default)
$backend = DatamatrixBackendFactory::Create($encoder);
// By default the module width is 2 pixel so we increase it a bit
$backend->SetModuleWidth($modulewidth);
// Set Quiet zone
$backend->SetQuietZone($quietzone);
// Set other than default colors (one, zero, quiet zone/background)
$backend->SetColor($color1, $color0, $colorq);
// Create the barcode from the given data string and write to output file
try {
$backend->Stroke($data,$outputfile);
} catch (Exception $e) {
$errstr = $e->GetMessage();
echo "Datamatrix error message: $errstr\n";
}
?>
【问题讨论】:
-
输出的是图片?如果是,你可以这样做:将图像保存在文件夹中并将路径保存在数据库中(推荐)或将图像直接保存为 blob 在数据库中(不推荐)
标签: php gs1-datamatrix