Wednesday, May 5, 2010

Postscript delegate failed for ImageMagick PHP library

For ImageMagick in PHP through the library Imagick the following error may occur for versions ImageMagick-6.3.5 to ImageMagick-6.4.2:
Postscript delegate failed `': No such file or directory

This is a bug and the error appears when one is trying to use the readimageblob function to read a PDF file.

The fix has been posted and the bug is no longer present. See So to fix it get the latest release from

Some installations (like server environments), haven't got the latest version and cannot install it. For these, it is possible to work around this bug, by using a temp file.

So instead of:
$im = new Imagick();

$im = new Imagick();
$temp = tmpfile();
fwrite($temp, $data);
fseek($temp, 0);

(This would typically be followed by for example:
$data = $im->getimageblob();


If this doesn't fix it for you, also check out:


  1. Hi, in what do you put in $data?
    Something like
    $data = file_get_contents("test.pdf"); ?
    Because even with this I have the same problem of missing file!

  2. Hi

    In this case I was working with a file that was uploaded to the server and then saved in my database in a BLOB field (see for an example). So the content of a file would be the result of the database statement.

    If you want to read data from a file (not a temp file like here) you would create the file handle $temp using the fopen function ( , also see
    When making the file handle directly, make sure the file is actually in the right folder. Use the file_exists function ( and make sure you are looking the right place (try "echo basename(dirname(__FILE__));" to see where you are, and have a look at

  3. First of all thanks for answering.
    I'm trying with this code

    /* FILE PATH */
    $pdf_filepath = "test.pdf";
    $thumbnail_filepath = "test.jpg";

    $im = new Imagick();

    if( file_exists($pdf_filepath) )
    $data = fopen($pdf_filepath,"rb");
    $temp = tmpfile();
    fwrite($temp, $data);
    fseek($temp, 0);

    $im->thumbnailImage(150, 240);
    $result = $im->writeImage($thumbnail_filepath);

    And there comes out a new error.

    Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `/tmp/magick-XXyyfNSm'' in /addons/jpgtopdf.php:73 Stack trace: #0 /addons/jpgtopdf.php(73): Imagick->readimagefile(Resource id #4) #1 {main} thrown in /addons/jpgtopdf.php on line 73

    So it seems that the problem is not anymore about the file itself, but the file coding. Any idea? :(
    Thank you very much!

  4. Hi

    Looks like your code is correct, yes. I think you are missing libraries/delegates for Imagick to read either your PDF file or convert it to JPEG files. ImageMagick doesn't always include these libraries by default.

    Try to use different image formats to see if this is the case, e.g. use a GIF file instead of PDF and same with JPEG. Might be clearer if you try to do it in command line using "convert".

    To see if you have the right delegates try:
    "convert -list configure"
    And look for the line starting with DELEGATES. The list should contain 'jpeg' for JPEG and 'gs' for PDF.
    Or "identify -list format" and look for JPEG to listed with 'rw'(read/write).

    ImageMagick delegates can be downloaded from

    If it is PDF decoding that is failing, you might be missing GhostScript. Download it from the delegates page or .

    (I get the following error on my windows machine when I don't have GhostScript installed:
    Magick: Postscript delegate failed `test.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/663.
    Magick: missing an image filename `test.gif' @ error/convert.c/ConvertImageCommand/2974.

    Also have a look at: