3
votes

I'm having problems with reading a file with Imagick. I've installed the imagick and ghostscript extension successfully.

This is what I'm doing:

<?php

    $im = new Imagick();
    $im->setResolution(300, 300);
    $im->readImage('/Applications/MAMP/htdocs/mywebsite/wp-content/plugins/myplugin/uploads/magazine_cover.pdf[0]');
    $im->setImageFormat('jpg');
    header('Content-Type: image/jpeg');
    echo $im;

?>

I'm getting the error:

Fatal error: Uncaught exception 'ImagickException' with message 'Failed to read the file' in /Applications/MAMP/htdocs/imagick.php on line 10

When I try to execute the following command in my terminal:

convert magazine_cover.pdf magazine_cover.jpeg

I'm getting a warning:

**** Warning: considering '0000000000 XXXXX n' as a free entry.

**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.11.3 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

But he created the jpeg ... . Why doesn't this work in the browser?

1
@isnisn: I've looked at that topic and tried to do . '[0]' . Also my file is readable so no solution .. - nielsv
I assume you have checked file permissions and user:group? - isnisn
@isnisn: file permission are on 777. What do you mean with user:group? - nielsv
@nielsv Did you fix this? I'm having the same issue. File is readable, file exists, path is correct, still throws an error. - hfingler

1 Answers

0
votes

Well the warning is generated by Ghostscript, it says your PDF file is not technically legal, but it should process just fine, unless there are more problems.

I would suggest you find out what command ImageMagick is passing to Ghostscript and try that on the command line. If it works then the problem is most likely at IM's end, otherwise the problem is that Ghostscript doesn't like your PDF file. The command line will probably give you more information. Even if it doesn't with that information and the file you can open a Ghostscript bug report and it can be fixed (if possible).