Error in readImage using Imagick()

Asked

Viewed 322 times

1

I am trying to convert a pdf into image using the Imagick library as follows:

<?
header('Content-type: image/jpeg');
$imagick = new Imagick();
// O myfile se encontra na mesma pasta do arquivo que estou executando
$imagick->readImage('myfile.pdf');
$imagick->writeImages('myfile.jpg', false);

I’m having the following mistake:

Fatal error: Uncaught Exception 'Imagickexception' with message 'Unable to read the file: Myfile.pdf' in /Users/myuser/teste.php:11 Stack trace: 0 /Users/myuser/test.php(11): Imagick->readimage('Myfile.pdf') 1 {main} thrown in /Users/myuser/teste.php on line 11

What could be?

1 answer

1


Try with the complete directory for the image:

$image->readImage($_SERVER['DOCUMENT_ROOT'] . '/dir_da_imagem/myfile.pdf');
$imagick->writeImages($_SERVER['DOCUMENT_ROOT'] . '/dir_da_imagem/myfile.jpg', false);

Where dir_da_image is the relative directory of myfile.pdf. Other than that, check the permissions of myfile.pdf and if the file is not corrupted.

  • Thanks for the reply, I made the above changes, I gave 777 permission to the file also to ensure, tested with is_readable() to make sure that the file can be read further has not worked yet.

  • Do you have Ghostscript (http://www.ghostscript.com/) installed? This may be a cause as well. Apparently, Imagick uses Gs to convert Pdfs.

  • I installed using: Brew install php56-Imagick --with-Ghostscript I restarted apache too but nothing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.