Php imagick with pdf question

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 the error message:

Uncaught exception 'ImagickException' with message 'unable to open image

If I changed:

$im = new imagick('/images/test.pdf[0]');

in

$im = new imagick('/images/test.pdf');

I get the following error:

Uncaught exception 'ImagickException' with message 'Unable to read the file

I'm sure the path to my PDF is correct, and I'm not sure how to solve this. Can anyone help me with this?

0
source share
1 answer

Do you have a /images folder in the ROOT of your drive? Remember - imagick works in PHP and has no idea what the structure of your site’s URL space is. You need to use the local file system path, for example

 $im = new imagick('/path/to/example.com/html/images/test.pdf[0]'); 
+1
source

Source: https://habr.com/ru/post/971488/


All Articles