I have installed ImageMagick on Windows with the DLL for imagick PHP.
I need to convert PDFs into JPEGs. So I also installed Ghostcript.
If I run this command:
convert rose.pdf rose.jpg
it works well. But if I try to reproduce this same functionality in my web environment with PHP:
$im = new imagick('test_pdf.pdf[0]' );
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(100);
$im->setImageFormat('pdf');
$im->writeImage('thumb.jpg');
then my page goes down.
I assume that Imagick PHP fails with PDF to JPEG, because it doesn't know how to use the Ghostscript library gslib
.
With this code, however, I can convert PNG to JPEG.
I tried to edit in delegates.xml
but I'm not exactly sure how this should be done.
Here are the relevant lines from my delegates.xml
:
<delegate decode="pdf" encode="eps" mode="bi" \
command=""@PSDelegate@" \
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 \
-dEPSCrop \
-sDEVICE=epswrite "-sOutputFile=%o" -- "%i""/>
<delegate decode="pdf" encode="ps" mode="bi" \
command=""@PSDelegate@" \
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 \
-dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 \
-sDEVICE=pswrite "-sOutputFile=%o" -- "%i""/>
Update
I tried to run the ImageMagick with -verbose
in order to get additional hints:
convert -verbose 2.pdf 1.jpg
Result:
[ghostscript library] Files/gs/gs9.15/bin/gswin64c.exe" -q -dQUIET -dSAFER -dBATCH
-dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2
"-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"
"-sOutputFile=C:/Users/Usuario/AppData/Local/Temp/magick-PjagmlB-%08d"
"-fC:/Users/Usuario/AppData/Local/Temp/magick-1l5fdY8X"
"-fC:/Users/Usuario/AppData/Local/Temp/magick-Fr-GsA3"
C:/Users/Usuario/AppData/Local/Temp/magick-_PjagmlB-000000
1 PNG 609x791 609x791+0+0 8-bit DirectClass 47.8KB 0.016u 0:00.031
2.pdf PDF 609x791 609x791+0+0 16-bit DirectClass 47.8KB 0.000u 0:00.031
2.pdf=>1.jpg PDF 609x791 609x791+0+0 16-bit DirectClass 131KB 0.031u 0:00.046 –
Result from Apache error Log
[Mon Dec 22 09:11:59.022854 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00428: Parent: child `process 6552 exited with status 255 -- Restarting. [Mon Dec 22 09:11:59.170587 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00455: Apache/2.4.9 (Win64) PHP/5.5.12 configured -- resuming normal operations -- PHP/5.5.12 configured -- resuming normal operations [Mon Dec 22 09:11:59.170587 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:42:59 [Mon Dec 22 09:11:59.170587 2014] [core:notice] [pid 6600:tid 520] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d C:/wamp/bin/apache/apache2.4.9' [Mon Dec 22 09:11:59.170587 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00418: Parent: Created child process 4484 [Mon Dec 22 09:11:59.807339 2014] [mpm_winnt:notice] [pid 4484:tid 436] AH00354: Child: Starting 64 worker threads.
I made a var_dump when the PDF its loaded
$im = new imagick( __DIR__ . DIRECTORY_SEPARATOR .'test_pdf.pdf' );
var_dump($im);die;
But the page goes down before enter in var_dump.
TEST SCENARIOS
- PDF to JPG using PHP on the CommandLine > works
- PDF to JPG using PHP-FPM from browser > doesn't work (error above)
- JPG to PDF using PHP-FPM from browser > works
-verbose
to your successful PDF conversion command? Runconvert -verbose rose.pdf rose.jpg
. You'll see the Ghostscript command which is called by ImageMagick. Maybe this gives you a hint about what you need to change in your Imagick setup... – Kurt Pfeifle[ghostscript library] Files/gs/gs9.15/bin/gswin64c.exe"
part a bit strange. Are you sure you copy'n'pasted it correctly?!? -- I'm guessing this should be"C:/Program Files/gs/gs9.15/bin/gswin64c.exe"
– Kurt Pfeifle