PHP Imagick / ImagickException: "no decode delegate for postscript or PDF files"

May 17th, 2013

Warning: This post is 10 years old. Some of this information may be out of date.

This morning I had an issue with a PHP imagick ImagickException when converting a PDF/postscript file to a thumbnail. I have PHP Imagick, Imagemagick and Ghostscript installed and everything verifies as OK in phpinfo output. The error is:

ImagickException: no decode delegate for this image format \`/' @ error/constitute.c/ReadImage/532 

My code:

$im = new Imagick("$pdf_filename[0]");
$im->thumbnailImage(150, 220);

This is a known bug (see and is fixed in the latest releases. Unfortunately the fixes haven't made it into our server's packages yet (Ubuntu precise64 / PHP Imagick 3.1.0RC2). The fix is to read the file from a file pointer rather than direct.

$pdf_filename = '01.pdf';
$thumbnail = '01.jpg';
$f = fopen($pdf_filename, 'r');
fseek($f, 0);
$im = new Imagick();
$im = $im->flattenImages();
$im->thumbnailImage(150, 220);

Initially it worked but thumbnails were being generated with black backgounds. Adding the call to $im->setColorSpace(imagick::COLORSPACE_RGB); resolved that.

Many thanks to Åsmund Herikstad for posting the solution that led me to the issue at