$path=getcwd();
$rawstring = $_POST['img_data'];
$malestr = str_replace("data:image/jpeg;base64,", "", $rawstring);
$img = new Imagick();
$img->readImageBlob($malestr);
$img->writeImage($path."/media/import/new.jpg");
这是我的 Imagick 函数,我正在尝试使用 Base64 编码数据编写图像。它的 throw 错误 .
“此图像格式没有解码委托(delegate)”
最佳答案
根据手册,Imagick::readImageBlob
需要一个二进制字符串,而您为其提供一个 base64 编码的字符串。首先使用函数 base64_decode
解码字符串,并将结果提供给 readImageBlob
。
// your code above
$malestr = str_replace("data:image/jpeg;base64,", "", $rawstring);
$malestr = base64_decode($malestr);
if (!$malestr) die('Unable to decode the string');
$img = new Imagick();
$img->readImageBlob($malestr);
关于php - 此图像格式没有解码委托(delegate) - Imagick - php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26646318/