所以,我使用以下代碼:
$currentIMG = imagecreatefromstring(base64_decode($img));
其中 $img 是 base64 字串。當我回顯 base64_decode($img) 時,它向我顯示一個字串(應該如此),但是當我使用 imagecreatefromstring() 時,它顯示以下錯誤:
致命錯誤:未捕獲錯誤:GdImage 類的物件無法轉換為字串
我可以保證 base64 字串沒有損壞,因為它適用于在線 base64 到影像轉換器,所以我無法弄清楚是什么問題。
提前致謝!
代碼:
function base64toImage($img) {
$currentIMG = imagecreatefromstring(base64_decode($img));
echo $currentIMG;
}
uj5u.com熱心網友回復:
而不是做:
echo $currentIMG;
嘗試將 a 列印GDImage為字串,請使用以下內容:
Header('Content-type: image/png');
imagepng($currentIMG);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/398928.html
