Imagick / imagick

🌈 The Imagick PHP extension 🌈
http://pecl.php.net/imagick
Other
550 stars 145 forks source link

php_imagick conversion fails on PHP 7.2 & Windows Server 2016? #321

Open andyperks opened 4 years ago

andyperks commented 4 years ago

Hi there,

We have ImageMagick plus the Imagick PHP extension installed on a Windows 2016 environment running PHP 7.2 (full version details outlined at the bottom of this issue).

We are using this primarily to convert PDFs to TIFs (one at a time during a transaction).

The conversion is failing in this particular infrastructure setup, but when we run a test using just the command line with ImageMagick on this infrastructure, it works just fine.

The conversion in our app also works on a LAMP stack (CentOS and PHP 7.2 again) but running slightly earlier versions of ImageMagick & php_imagick. It also runs on Windows when running slightly older versions, however the very same versions don't appear to be available for Windows + PHP 7.2.

We've distilled the general approach we need to take in our app into the attached simplified test script, using https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf as the PDF to attempt to convert.

When attempting to convert on the problematic stack, the system just hangs with no real useful information logged, so wondering if there could be a conversion bug in the specific version of the php_imagick library when running on a Windows PHP 7.2 environment?

Specific problematic versions when running this script from hat we can tell are as follows:

We do need the system to be on PHP 7.2.x and Windows 2016.

Are there any known issues or advice that can be provided around this at all please if you are able to recreate? Let me know if more info required...

Many thanks in advance

tiff_test.php.txt

Danack commented 4 years ago

Hi @andyperks,

tbh, I'm not going to spend time trying to recreate it myself - I really dislike Windows and am generally "not happy" about the time/reward I have for this project. Trying to reproduce a bug from scratch takes a huge amount of time. Getting into the habit of making a reproduce case with a docker (or similar) container is something that would make it easier for other people to investigate your bugs.

"if there could be a conversion bug in the specific version of the php_imagick"

Unlikely....the Imagick library itself doesn't really do that much, most of the functions are just thin wrappers to the underlying ImageMagick library.

Some things I would suggest:

i) Use a different version of Ghostscipt.

ii) Compare the 'policy files' that ImageMagick uses e.g. policy.xml for the working version and non-working version. Those include how the delegate programs (like ghostscript) are called and maybe there could be something borken there.

iii) There are tools on Windows that allow you to see what system calls are being made. If "the system just hangs with no real useful information logged" then this should be identifiable as a particular system call. Though it could also be something getting stuck in a loop which might not be as identifable.

iv) Is this code for debugging purposes? Or is there another reason for not using the imagick writeImage function?

$fh = fopen($pdfPathMinusExt . '-' . $i . '.' . $format, "w");
    if ($fh) {
        fwrite($fh, $page->getImageBlob());
        fclose($fh);
    } else {
        throw new Exception("Could not write image file (" . $pdfPathMinusExt . '-' . $i . '.' . $format . ")");
    }

I am a little suspicious of using $imagick->getImageBlob() ... it does appear to have a slightly different set of bugs compared to just writing the image directly to disk.

btw Your code is actually quite simple...if the command line version works fine for you, it would probably make sense just doing the conversion by calling the command line ImageMagick tool directly through exec or similar...

Also, it would be worth trying it via the command line anyway, as there could be a permissions issue for the server, vs the CLI.

Danack commented 4 years ago

oh - apparently you should definitely check the policy files: https://stackoverflow.com/questions/52703123/override-default-imagemagick-policy-xml

hifihedgehog commented 4 years ago

am generally "not happy" about the time/reward I have for this project.

We (us silent lurkers) are so grateful for all you do to contribute to this project. :) So if there is anything at all we can do to help to get the PHP 7.4 patched release out, anything at all, just let us know.