My goal is to extract about 30 JPG or PNG images from a PDF using PHP. I’m using ImageMagick from PHP in a shared hosting. Imagick::readImage. (PECL imagick ). Imagick::readImage — Reads image from filename. Description. bool Imagick::readImage (string $filename). Example case: extract page 1 of a pdf file and save it as jpg image. $i = new Imagick(); $i->setResolution();.
|Country:||Saint Kitts and Nevis|
|Published (Last):||1 July 2016|
|PDF File Size:||4.19 Mb|
|ePub File Size:||16.86 Mb|
|Price:||Free* [*Free Regsitration Required]|
Read page 1 from test.
I solved it by encoding it correctly, but the answer marked as correct is a much better solution. This doesn’t work with the url: I guess what I should do in that case is to break up every part of the url omagick encode all different parts in some way. Sign up or log in Sign up using Google.
I’m using ImageMagick 6. The code above works for the first X pages, then fails with an exception. It always gives an exception in the readImage command when index is around 15 or higher depending on the source PDF.
The fix for me was finding the tmp directory and setting the correct permissions for it. As umagick in my answer: The error seems to be consistent through this whole domain, but sometimes it’s different from image to image on the same domain.
The Blue Dog 2, 3 14 Is there an alternative solution? It is not running a loop and finally getting the exception on the 16th page. So I figured out I needed to encode the url properly. The functions setImageFormat and setFormat, programmed line after line, provided no effect to changing the imagjck to png, bmp, or gif. The problem is that Imagick can’t handle the uri format.
ReadImage takes a string containing the folder location of the file, and ReadImageFile takes a handle pointing to the file location. Victor Bocharsky 6, 5 35 Do you have access to PHP execso that you could run the command line and see if that fails?
Reads image from filename
Try to use urlencode function for encode special chars of url:. Sign up using Email and Password. Uday Hiwarale 1, 16 It seems that when you are reading a page that is far enough into the PDF file, it gets the exception.
Email Required, but never shown. Based by looking at the pages, you would think that they behave the exact same, except in their arguments: Initially, the first looks far more tempting, since you don’t have to worry about fopen and fclose commands. I tried the same test on another hosting account with PHP 7. I’m not sure if this code is optimal, but it works. It opens up new errors, it dose’t even understand the url.