-1

I'm unable to make imagick works with local xampp.

Error

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

Code

$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();
Pk boss
  • 274
  • 1
  • 13
  • Poss duplicate of [this post](http://stackoverflow.com/questions/22547819/imagick-not-loading-images-with-nodecodedelegateforthisimageformat-error-mess) –  Sep 11 '14 at 06:46
  • Welcome to StackOverflow. Please give a brief description of what you are trying to do, what you have tried to fix this issue and what your are expecting the output to be. – JamesENL Sep 11 '14 at 06:47
  • Wow, tough crowd today. @JeremyMiller It's not a duplicate, this is to do with PDFs. @ James Massey The question is brief, but it actually is complete. – Danack Sep 11 '14 at 15:04
  • @Danack It is quite related, but your answer is very targeted and extremely helpful. +1 –  Sep 11 '14 at 15:23

3 Answers3

1

Imagick calls the ImageMagick library to do all it's processing of images. The Image Magick library does not actually handle PDFs itself, it calls GhostScript to process them and generate a PNG or Jpeg which Image Magick then reads.

The NoDecodeDelegateForThisImageFormat is saying that Image Magick is unable to call the delegate program that it thinks it should be delegating the decoding to i.e. GhostScript.

The solution is to install GhostScript through yum or apt, and it 'should' work.

If it still doesn't work you should check what is in the delegates file for Image Magick (http://www.imagemagick.org/source/delegates.xml) for the PDF entry and make sure that it is callable from a command prompt - i.e. to check that Image Magick will also be able to find it.

Danack
  • 24,939
  • 16
  • 90
  • 122
0

Even after installing GhostScript, we could not get the imagick code to work after switching from AWS to Azure, getting the Delegate error. We ended up converting the PHP code to Image Magick command line, using the function execInBackground to run the command (PHP.net Exec() Page)

NOTE: The command line did not work using exec alone. The php script would not terminate normally.

//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);
Nicolas Giszpenc
  • 677
  • 6
  • 11
0

From my Server admin: You may want to try GraphicsMagick as an alternative to Image Magick.

Graphics Magick Homepage

Nicolas Giszpenc
  • 677
  • 6
  • 11