I'm using imagick to convert a pdf to a jpg in a script I have...it works fine if I give the direct path to the uploaded pdf without the page specified, but when I add the [0]
onto the end of the file path to specify that I only want to read the first page, it bombs out with the following error:
"Fatal error: Uncaught exception 'ImagickException' with message 'Invalid filename provided' Imagick->readImage()"
I've also tried using '/path/to/file.pdf[0]'
directly in the constructor with no luck, but without the page specifier, that also works fine.
According to the documentation...this should work. What am I doing wrong here?
$doc_preview = new Imagick();
$doc_preview->setResolution(180,180);
$doc_preview->readImage('/path/to/file.pdf[0]');
$doc_preview->setImageFormat('jpeg');
$doc_preview->writeImage('/path/to/file.jpg');
$doc_preview->clear();
$doc_preview->destroy();
UPDATE: I should have mentioned I am using HHVM. Not sure this would make a difference in this case...but I am.
UPDATE2: I have opened an issue over on the HHVM github repo. Hopefully they will fix this bug...until then, the answer I have marked correct below is a decent (albeit hacky) workaround.