Pear Barcode 2-保存到磁盘


Pear Barcode 2 - save to disk

我正在使用Pear Barcode2生成gif条形码。

这目前是有效的,我可以看到图像作为gif图像文件。因此页面不是以HTML形式显示的,而是作为独立图像显示的。

我的代码是:

$small_graph_height = 55;
        $small_graph_width = 1.2;
        $large_graph_height = 55;
        $large_graph_width = 1.14;
        $type = "gif";
        $code = "code39";
        $to_browser = TRUE;
          include_once "application/libraries/Image/Barcode2.php";
        $ticketno='TDN4993';
              $productserial_str = empty($productserial_str) ? ucfirst($ticketno) : $productserial_str;
              $productserial_type = $code;
              $productserial_imgtype = $type;
              $productserial_bSendToBrowser = $to_browser;
              $productserial_height = $large_graph_height;
              $productserial_width = $large_graph_width;
              $productserial_img = Image_Barcode2::draw($productserial_str, $productserial_type, $productserial_imgtype, $productserial_bSendToBrowser, $productserial_height, $productserial_width);
              ob_start();
                imagepng($productserial_img);
                $productserial_imgBase64 = base64_encode(ob_get_contents());
              ob_end_clean();
              imagedestroy($productserial_img);
               $image= '<img class="ProductSerial" src="data:image/' . $productserial_imgtype . ';base64,' . $productserial_imgBase64 . '">';
            echo $image;

我想做的是将这个图像直接保存到服务器硬盘上,而不是显示给用户。

我试过使用PHP的imagegif,但它不喜欢$image是字符串格式。

欢迎任何建议。一如既往地感谢

如果需要将图像保存在磁盘上,则需要使用imgpng()函数。

我从这里得到的一个例子。

imagepng($bc->draw($data, $type, 'png', false),'ur_image_location'); 
$small_graph_height = 55;
$small_graph_width = 1.2;
$large_graph_height = 55;
$large_graph_width = 1.14;
$type = "gif";
$code = "code39";
$to_browser = TRUE;
include_once "application/libraries/Image/Barcode2.php";
$ticketno='TDN4993';
$productserial_str = empty($productserial_str) ? ucfirst($ticketno) : $productserial_str;
$productserial_type = $code;
$productserial_imgtype = $type;
$productserial_bSendToBrowser = $to_browser;
$productserial_height = $large_graph_height;
$productserial_width = $large_graph_width;
$productserial_img = Image_Barcode2::draw($productserial_str, $productserial_type, $productserial_imgtype, $productserial_bSendToBrowser, $productserial_height, $productserial_width);
ob_start();
imagepng($productserial_img);
$png = ob_get_contents();
ob_end_clean();
file_put_contents('barcode.png', $png);
echo 'image saved to file barcode.png';