php如何将TCPDF png条码保存到指定文件夹?

How to save TCPDF png barcode to a specified folder in php?

我可以使用以下代码使用 TCPDF 生成条形码:

$barcodeobj = new TCPDF2DBarcode('http://www.tcpdf.org', 'QRCODE,L');
$barcodeobj->getBarcodePNG(6, 6, array(0,0,0));

我不想在屏幕上显示条形码,而是想将 png 条形码保存到指定的文件夹,我查看了文档但找不到如何实现这一点。 (我知道如何保存生成的 PDF)。

如有任何帮助,我们将不胜感激。

谢谢

简单 :

而不是

$barcodeobj->getBarcodePNG(6, 6, array(0,0,0));

使用:

$file_png = "Pictures/barcode.png";
file_put_contents($file_png, $barcodeobj->getBarcodePngData());

就这些了。

关于 TCPDF 库的重要说明:

A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this version will not receive any additional development or support. This version should be considered obsolete, new projects should use the new version as soon it will become stable.

为了生成线性和二维条码,有单独的库: https://github.com/tecnickcom/tc-lib-barcode

要使用 tc-lib-barcode 库将条码保存为图像:

$bobj = $barcode->getBarcodeObj('CODABAR', '123456', -3, -30, 'black', array(0, 0, 0, 0));
$destination_folder = "uploads/barcode.png";
file_put_contents($destination_folder, $bobj->getPngData());