Converting a PDF to an image using Gmagick in PHP renders a very poor quality image.
The solution in Imagick was to call setResolution(x,y)
before loading the PDF file. This would change the -density option.
There is no setResolution(x,y)
in Gmagick, and unfortunately, calling setimageresolution(x,y)
just throws an error:
PHP Fatal error: Uncaught exception 'GmagickException' with message 'Can not process empty Gmagick object'
Calling setimageresolution(x,y)
after loading the PDF has no effect, and I can't find a way to set the -density option before loading the file.
EDIT: I would be happy for a way to set the default density system-wide. I do have root access.
I bumped into a similar problem and solved it with the following code:
Note that the
setresolution
method is not documented in PHP anywhere, but it seems to work – at least for me.