views:

673

answers:

1

Hi All,

This question was close, but doesn't do the trick. I am trying to convert a pdf into a jpg (for thumbnailing). Here is the command I am running:

convert -quality 100 -density 200x200 /path/file.pdf /path/file.jpg

I have mamp pro 1.7.2,imagemagick, ghostscript all properly installed and working. This command works perfectly from a shell but fails when being run from within a php script. Another twist, is for an image to image conversion, things work perfectly from both shell and script. That would lead me to believe there is some path issue relating to ghostscript (gs) from within the apache/php environment although the gs binary is sitting in the same directory as the convert binary. Also, I had tweaked the mamp apache envars per (brybot.ca's excellent tutorial -- www.brybot.ca/archives/getting-imagemagick-and-more-to-work-with-mamp-on-os-x/) so ImageMagick is working great AND "/opt/local/bin" is in my apache path variable.

Via a shell, the conversion from pdf to image takes a few moments and I have a nagging thought that the php script is terminating/finishing before the imagemagick / ghostscript conversion is complete and possibly aborting the imagemagick conversion process...? I have tried exec, system, shell_exec all to no avail.

I get no output from the command nothing seems to happen and nothing showing up in apache or php logs.

UPDATE: Now I'm getting the following error in apache log after restarting MAMP

convert: unable to create temporary file `/path/file.pdf': Permission denied @ pdf.c/ReadPDFImage/358. convert: missing an image filename `/path/file.jpg' @ convert.c/ConvertImageCommand/2766.

Anyone have any ideas? I'm pulling my hair out on this...

Thanks so much!

+1  A: 

Apache usually has limited permissions on your server (and that's how you want it to be), try putting the files into /tmp where you know apache has write permissions. Apache might also have trouble reading files that were created by other users, unless they are world-readable.

too much php
Thanks for the thought, I was thinking along the same lines. Files are being read just fine evidenced by the fact that image to image conversions are working just not any conversions involving pdfs (ghostscript related).