2014-09-11 549 views
-1

我無法使imagick與本地xampp一起工作。致命錯誤:未捕獲異常'ImagickException'帶消息'NoDecodeDelegateForThisImageFormat

錯誤

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(); 
+0

POSS複製[此篇](http://stackoverflow.com/questions/22547819/imagick-not-loading-images-with-nodecodedelegateforthisimageformat-error-mess) – 2014-09-11 06:46:53

+0

歡迎的StackOverflow的。請簡要說明您正在嘗試做什麼,您嘗試解決此問題的方法以及您希望輸出的內容。 – JamesENL 2014-09-11 06:47:04

+0

哇,今天的艱難人羣。 @JeremyMiller這不是重複的,這是關於PDF的。 @ James Massey問題很簡單,但實際上已經完成。 – Danack 2014-09-11 15:04:18

回答

1

Imagick調用ImageMagick庫來完成所有它的圖像處理。 Image Magick庫本身並不實際處理PDF,它調用GhostScript來處理它們並生成Image Magick隨後讀取的PNG或Jpeg。

NoDecodeDelegateForThisImageFormat表示Image Magick無法調用它認爲它應該將解碼委託給GhostScript的委託程序。

解決方法是通過yum或apt安裝GhostScript,它應該可以工作。

如果它仍然不起作用,您應該檢查Image Magick的代表文件(http://www.imagemagick.org/source/delegates.xml)中的PDF條目,並確保它可以從命令提示符調用 - 即檢查Image Magick是否也會能夠找到它。

+0

我已經在我的windows(8.1)機器上安裝了GhostScript最新版本。還沒有運氣! – 2014-09-12 09:42:23

+0

如何對Image Magick說,在哪裏可以找到GhostScript,如果GS安裝在C:\ ghostscript上的Windows上? – user3383675 2016-09-22 06:34:33

0

即使在安裝GhostScript之後,我們也無法從AWS切換到Azure後得到代表錯誤的imagick代碼。我們結束了使用功能execInBackground運行命令(PHP.net Exec() Page

注意的PHP代碼轉換爲難懂的命令行,:在命令行沒有單獨使用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); 
相關問題