2014-06-09 45 views
0

我一直在試圖通過電子郵件發送一個包含fieldname-value列表的表。當我達到圖像值時,我濾除圖像字符串以用於tcpdf圖像輸出。我做了一個條件,如果data:image/png被發現,它應該被刪除。否則,請刪除數據:image/jpeg。php tcpdf圖像字符串過濾器

$pdf->writeHTMLCell(50, 0, '', '', "{$fieldname}", 1, 0, 0, true, 'R', true); 

$base64 = strpos("data:image/png", $col_value) ? str_replace("data:image/png;base64,", "", $field_value) : str_replace("data:image/jpeg;base64,", "", $field_value); 

$imgdata = base64_decode($base64); 

$pdf->Image('@'.$imgdata, '', '', 0,65, '', '', 'B', false, 300, 'R'); 

$pdf->writeHTMLCell(0, 10, '', '', "", 1, 1, 0, true, '', true); 

導致:

TCPDF ERROR: [Image] Unable to get the size of the image: @

沒有條件/做一個的if/else爲$的base64值,我沒有得到錯誤。但是我的base64不會像兩種類型那樣靈活。

回答

0

終於明白了! explode()工作...然後,而不是PDF->圖像,我只是把一個臨時工。 img標籤的src屬性的圖像。

  • 獲得與getimagefromstring
  • 字符串從字符串保存一個臨時圖像
  • 然後在$ PDF-使用img標籤> writeHTMLCell

    $base64 = explode(',', $col_value); 
    $base64d = base64_decode($base64[1]); 
    
    $im = imagecreatefromstring($base64d); 
            if ($im !== false) { 
             echo 'image ok'; 
             //header('Content-Type: image/png'); 
             imagejpeg($im, $path . "test.jpg"); 
             imagedestroy($im); 
             echo "<br /> image done"; 
            } 
            else { 
             echo 'An error occurred.'; 
            } 
    $pdf->writeHTMLCell(0, 30, '', '', '<img src="' .$path . 'test.jpg"/>', 1, 1, 0, true, 'C', true); 
    unlink($path . "test.jpg");