问题
I am trying to convert the first page of a PDF to an image file.
I have the following code:
$im = new imagick('/images/test.pdf[0]');
$im->setImageFormat("jpg");
$page=$im->queryFormats();
echo "<pre>";
print_r ($page);
echo "</pre>";
However, I get an error message saying:
Uncaught exception 'ImagickException' with message 'unable to open image
If I change:
$im = new imagick('/images/test.pdf[0]');
to:
$im = new imagick('/images/test.pdf');
I get the following error:
Uncaught exception 'ImagickException' with message 'Unable to read the file
I am sure the path to my PDF is correct and I'm not sure how to solve this. Can anyone help me out with this?
回答1:
Do you have a /images
folder in the ROOT of your drive? Remember - imagick is running within PHP and has no clue whatsoever what your site's URL-space structure is. You need to use the local file system path, e.g.
$im = new imagick('/path/to/example.com/html/images/test.pdf[0]');
来源:https://stackoverflow.com/questions/15955013/php-imagick-with-pdf-issue