致命错误:带有消息'NoDecodeDelegateForThisImageFormat的未捕获异常'ImagickException'

时间:2014-09-11 06:39:58

标签: php imagick

我无法用本地xampp制作想象力的作品。

错误

Fatal error: Uncaught exception 'ImagickException' with message 'NoDecodeDelegateForThisImageFormat

代码

$im = new imagick();
$im->setResolution(300, 300);
$im->readimage($base_dir . 'files/PDF/test.pdf');
$im->setIteratorIndex($i);
$im->setImageFormat('jpeg');
$newimgname = time();
$im->resizeImage(500, 500, Imagick::FILTER_LANCZOS, 1);
$im->cropImage(100, 100, 0, 0);
$thumbnail = $im->getImageBlob();

3 个答案:

答案 0 :(得分:1)

Imagick调用ImageMagick库来完成它所有的图像处理。 Image Magick库实际上并不处理PDF本身,它会调用GhostScript来处理它们并生成一个PNG或Jpeg,然后Image Magick会读取它。

NoDecodeDelegateForThisImageFormat表示Image Magick无法调用它认为应该将解码委托给GhostScript的委托程序。

解决方案是通过yum或apt安装GhostScript,它应该'工作

如果它仍然无法正常工作,您应该检查图像Magick(http://www.imagemagick.org/source/delegates.xml)的委托文件中PDF条目的内容,并确保它可以从命令提示符调用 - 即检查Image Magick也能找到它。

答案 1 :(得分:0)

即使在安装GhostScript之后,我们也无法在从AWS切换到Azure后获得imagick代码,从而获得Delegate错误。我们最终将PHP代码转换为Image Magick命令行,使用函数execInBackground运行命令PHP.net Exec() Page

注意:命令行无法单独使用exec 。 php脚本不会正常终止。

//from PHP.net 
function execInBackground($cmd) { 
    if (substr(php_uname(), 0, 7) == "Windows"){ 
        pclose(popen("start /B ". $cmd, "r"));  
    } 
    else { 
        exec($cmd . " > /dev/null &");   
    } 
}

//create a thumbnail from the first page of PDF
//old php code
/*
$image_magick = new imagick(); 
$image_magick->setbackgroundcolor('white');
$image_magick->readImage($file_path . "[0]");
$image_magick = $image_magick->flattenImages();
$image_magick->setResolution(300,300);
$image_magick->thumbnailImage(102, 102, true);
$image_magick->setImageFormat('jpg');
$image_magick->writeImage($thumbnail_path);
*/

//command line syntax
$cmd = "magick convert " . chr(34) . $file_path . "[0]" . chr(34) . " -background white -flatten -resample " . chr(34) . "300x300" . chr(34) . " -thumbnail " . chr(34) . "102x102" . chr(34) . " -format jpg -write " . chr(34) . $thumbnail_path . chr(34);
execInBackground($cmd);

答案 2 :(得分:0)

从我的服务器管理员: 你可能想尝试使用GraphicsMagick作为Image Magick的替代品。

Graphics Magick Homepage

相关问题