-
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDF with links converted to JPGs get black border around them on Alpine linux #571
Comments
The error could be in ghostscript, which is probably doing the conversion from PDF to a pixel based format. Can you try doing the conversion manually, by invoking ghostscript with something like:
And see if that shows the same problem on the alpine box, and works as expected locally? Also, can you then say which ghostscript version you're using? You may be able to get a better version of Ghostscript from https://ghostscript.com/releases/gsdnld.html |
Thanks for the quick reply!
That seems to generate a (quite large) PNG file without any borders, so that is one step closer at least 😄 Does Imagemagick use Ghostscript to convert to PNG first, then JPG?
|
Tried this now (both the x86_64 and just x86 versions) and when trying to execute the |
It should be, both to avoid image quality loss in using JPG and also to preserve transparency in the image. Can you run your test script through strace with a command similar to:
That will produce a lot of info. In it there should be an invocation of ghostscript. Can you find that and paste the exact thing it's running?
Actually, if running it by hand generates a correct image, you don't need to worry about finding a better version of ghostscript, probably. Just need to find why it's not producing the right image through ImageMagick. |
Thanks! I ran the strace and attached it here. I tried browsing through it myself but it wasn't clear to me how it executes ghostscript to generate the PNG and then the JPEG file. This was generated on an instance where the imagick extension was installed via pecl btw. I could generate one from an instance where it has been installed with the apk package instead if that is needed? |
It apparently doesn't; apparently it is possible to compile ImageMagick with the option:
set to almost certainly compile against Ghostscript as a library, not a delegate, so there is no command line invocation. Which is slightly unfortunate as it means you can't just replace the version of Ghostscript on your machine. Out of interest, can you dump the result of However to address your issue....I probably won't be able to fix it, as it's out of my control. I think you have two options i. Go to report a bug against https://pkgs.alpinelinux.org/package/v3.3/main/x86/imagemagick and ask them to use a less buggy version of Ghostscript and hopefully fix it there. ii. Just install a known working version of Ghostscript on your image processing box, and invoke it with exec(). |
Sure! Among the configure options there is a
|
Yes, sorry I should have listed that. You would need to recompile ImageMagick, and then recompile Imagick from source to link against the newly built ImageMagick. Imagick can be compiled either through pecl or downloading the source and then:
Yeah....tbh although it's having everything 'just work' in one method call, the stack of software needed to load PDFs and then edit then as images is such a tall stack, that it shouldn't be too surprising it falls over. Using the precise tool to convert PDFs to PNGs, and then if necessary doing any processing afterwards is not only more likely to work, it's so much easier to debug if something breaks. There is a very strong argument that I should divert people away from using Imagick for processing PDFs.... |
Working on my local machine (Pop OS) and using the PHP Imagemagick extension (PHP v8.1.13, Imagick v3.7.0), I try to convert a PDF to JPGs. The PDF has links in it multiple places, and when I run my PHP script in a docker container with Alpine linux (3.16), the links get a thin black border around them. On my local machine, I do not get this.
The PDF in question is this.
Trying to convert the first page locally, I get this:
In my docker container I get this:
The output is the same as above if I use
convert file.pdf[0] foo.jpg
in the terminal.The difference is probably in how the imagemagick or the PHP imagemagick extension is installed locally vs. in the
php:8.1.13-alpine3.16
docker image. Locally I use the deb.sury.org repo and just install thephp8.1-imagick
package. In docker I have tried bothapk add php81-pecl-imagick
andpecl install -o -f imagick
, to no difference in the output generated I'm afraid.The OS packages for imagemagick differ a little bit though, being newer in the docker container (
ImageMagick 6.9.12-65 beta Q16 x86_64 17481
vs.ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25
locally).Debug related info
policy.xml
file used both places:Imagemagick related output from
php -i
locally:Imagemagick related output from
php -i
on alpine 3.16 (when installed with php81-pecl-imagick):Imagemagick related output from
php -i
on alpine 3.16 (when installed with pecl):Other packages installed in the docker container:
PHP code in question:
Any help to pinpoint where the problem lies would be highly appreciated
The text was updated successfully, but these errors were encountered: