Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've just spent the last three hours getting ImageMagick to play nicely with PHP for a PDF to JPG convert. Instead of documenting it myself locally, I figured I'd write it up here, with all the buzzwords and things I screwed up, so the next noob can save some time.</p> <p>Tested on two OSs,Windows 7 x64 and Vista x64, with PHP 5.2.8 and Apache 2.2.11.</p> <p>You'll need Ghostscript and ImageMagick. I got <code>gs871w64.exe</code> and <code>ImageMagick-6.6.3-0-Q16-windows-x64-dll.exe</code>.</p> <p>Do a basic install of ImageMagick (I'll call it IM now). Double check the system path variable to ensure you can IM from anywhere. It should point to the IM directory. Test the installation with this line in <code>cmd</code>: <code>convert test.gif test.jpg</code> (assuming you have <code>test.gif</code>). Works OK.</p> <p>Test a PDF convert (<code>convert test.pdf test.jpg</code>). You should get a (long) message about "gswin32c.exe" and "Postscript delegate failed" and "missing an image filename". That means IM can't find a PDF 'translator'. You need Ghostscript.</p> <p>Install Ghostscript (I'll call it GS now). I had to do it twice for some reason before it took. Add the 'bin' address in the GS folder to the system variable. Test the installation with <code>gswin32 test.pdf</code> and you should see your file pop up in the GS viewer. Important note: <strong>gs doesn't work</strong> in Windows (<code>'gs' is not recognized as an internal or external command, operable program, or batch file.</code>). You need to use <strong>gswin32</strong>.</p> <p>Back to the IM test: <code>convert test.pdf test.jpg</code> should work now.</p> <p>Now over to PHP - write up this script:</p> <pre><code>$out = shell_exec("convert blah.pdf blah2.jpg 2&gt;&amp;1"); echo $out; </code></pre> <p>The <code>2&gt;&amp;1</code> <a href="https://stackoverflow.com/questions/818255/in-the-shell-what-is-21">will move all errors into the standard output</a> so you can better diagnose stuff :). Now, your PHP script may run in the cmd prompt, but nothing happens when you run it in a browser. Smack your forehead and restart Apache.</p> <p><em>pant</em> Exhaustive and probably elementary, I know. But a hopefully helpful summary of approximately 20 pages of semi-helpful clues.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload