我是初学者。我正在尝试生成条形码并将其作为图像保存到“上传”文件夹中。
这是我的代码,但它不起作用。问题是什么?任何帮助将不胜感激。
// Including all required classes
require_once('class/BCGFontFile.php');
require_once('class/BCGColor.php');
require_once('class/BCGDrawing.php');
// Including the barcode technology
require_once('class/BCGcode128.barcode.php');
$font = new BCGFontFile('./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('hi'); // Text
$drawing = new BCGDrawing('../uploads/',$color_white);
$drawing->setBarcode($code);
$drawing->draw();
// Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
最佳答案
您必须设置正确的文件名。像这样:
$drawing = new BCGDrawing('../uploads/filename.png', $color_white);
或这个:
$drawing->setFilename('../uploads/filename.png');
关于php - 如何将生成的条形码作为 img 保存到文件夹中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21328705/