[英]php imagick - read image from base64
我用js操縱圖像,我想保存這些轉換后的圖像。 我用ajax發布這個數據:
image : canvas.toDataURL('image/jpeg')
這樣,我得到了圖像的base64代碼,但我找不到用Imagick讀取它的方法。
這是我的過程:
$img = new Imagick();
$decoded = base64_decode($_POST['image']);
$img->readimageblob($decoded);
但這失敗了:
致命錯誤:未捕獲異常'ImagickException',消息'此圖像格式沒有解碼委托',@ error / blob.c / BlobToImage / 360'/ Library / WebServer / Files / test / save.php:7堆棧跟蹤:
#0 /Library/WebServer/Documents/test/save.php(7):Imagick-> readimageblob('你?Z?f?{?? z ????? ...')
有什么想法嗎?
想通了。
我不得不刪除data:image/png;base64,
部分來自發布的字符串,然后imagick可以將其解釋為blob。
閱讀此網址; -
或試試: -
$thumbnail = $img->getImageBlob();
$contents = ob_get_contents();
ob_end_clean();
echo "<img src='data:image/jpg;base64,".base64_encode($contents)."' />";
readImageBlob - 從二進制字符串中讀取圖像: http ://php.net/manual/en/imagick.readimageblob.php
$base64 = "iVBORw0KGgoAAAAN....";
$imageBlob = base64_decode($base64);
$imagick = new Imagick();
$imagick->readImageBlob($imageBlob);
header("Content-Type: image/png");
echo $imagick;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.