Reputation: 3829
I'm trying to manage some PDFs using Imagemagick from PHP, using exec()
. I've simplified down my test case, and found that while PDFs are fine from the command line, they're not working in PHP.
From the command line:
$ identify /var/tmp/doc-98563.png
/var/tmp/doc-98563.png PNG 2550x3300 2550x3300+0+0 8-bit Gray 256c 1.24178MiB 0.000u 0:00.009
$ identify /var/tmp/doc-35765.pdf
/var/tmp/doc-35765.pdf[0] PDF 419x595 419x595+0+0 16-bit ColorSeparation CMYK 997321B 0.120u 0:00.119
/var/tmp/doc-35765.pdf[1] PDF 419x595 419x595+0+0 16-bit ColorSeparation CMYK 997321B 0.110u 0:00.109
Great! Correctly identifies my files, PNG or PDF.
I can also confirm permissions are just fine on the files:
$ ls -la /var/tmp/doc*
-rw-r--r-- 1 _www wheel 1.6M 15 May 10:05 /var/tmp/doc-35765.pdf
-rw-r--r-- 1 _www wheel 1.2M 15 May 10:01 /var/tmp/doc-98563.png
Running the equivalent from PHP...
exec('identify /var/tmp/doc-98563.png', $output, $exitcode);
var_dump($output);
var_dump($exitcode);
unset($output);
exec('identify /var/tmp/doc-35765.pdf', $output, $exitcode);
var_dump($output);
var_dump($exitcode);
...produces different results:
array(1) {
[0]=>
string(93) "/var/tmp/doc-98563.png PNG 2550x3300 2550x3300+0+0 8-bit Gray 256c 1.24178MiB 0.000u 0:00.000"
}
int(0)
array(0) {
}
int(1)
So the PNG works identically from both places (as is expected), but the PDF just... doesn't.
I've checked convert -version
and convert -list format
on both, and both are identical (ImageMagick 7.0.7-32, PDF PDF rw+ Portable Document Format
). I've also specific the full path /usr/local/bin/identify ...
to verify it's definitely running the same instance of IM. File permissions are identical for everything I can see related to PDF vs PNG, so don't think it's that.
Running gs
DOES work fine from PHP with the same file, but gs doesn't do what I need.
Anything else I can try?
For reference, I'm on OSX using PHP7.2, and both it and ImageMagick (and Ghostscript) are installed with Brew.
Upvotes: 0
Views: 47
Reputation: 53089
This is a common issue. It seems that the PHP environment typically cannot find Ghostscript. One way to solve that is to edit your installed delegates.xml file to put the full path to ghostscript, i,e., gs in all the entries for command=""gs". This would be for PDF, PS, EPS. Another way is to modify your PHP environment variables to put GS in your PHP PATH.
Upvotes: 1