Weird Errors with PDFs.
Posted: 2012-09-03T10:33:32-07:00
Hey guys.
I have image magic and ghostscript installed through macports, and have installed imagick and it's all working fine with images. pdf to jpg and vice versa works fine from the command line but it's not working when I try to run it through exec() from php. It creates a pdf file but it's not openable. So it seems like ghostscript is not working properly with imagemagick through php?
When I try to open a pdf image by creating a new imagick object ie:
$image = new imagick("passport.pdf");
This creates an error message like this:
Fatal error: Uncaught exception 'ImagickException' with message 'unable to create temporary file `passport.pdf': Permission denied @ error/pdf.c/ReadPDFImage/393' in /Users/hyun-hoshin/Documents/School_Work/Computing/Unit_4/Training/PHP/PHP_with_MySql_Beyond_the_Basics/Work/test.php on line 5
( ! ) ImagickException: unable to create temporary file `passport.pdf': Permission denied @ error/pdf.c/ReadPDFImage/393 in /Users/hyun-hoshin/Documents/School_Work/Computing/Unit_4/Training/PHP/PHP_with_MySql_Beyond_the_Basics/Work/test.php on line 5
It works fine for images though..
Do you have any Ideas?
EDIT!:
I've found the solution!!!
The problem was in the error message itself, it WAS a permissions error.
I found out that when image magick uses a delegate like ghost script, it needs to create a temporary file, and it either uses the default temporary file path TMPDIR or if you've set one, it uses MAGICK_TMPDIR. and I put in "set" in the command line, and the TMPDIR variable had the wrong permissions, as in it didn't allow any access to everyone, so it was just a simple case of changing those permissions so that apache could actually put in temporary files in to that directory.
I have image magic and ghostscript installed through macports, and have installed imagick and it's all working fine with images. pdf to jpg and vice versa works fine from the command line but it's not working when I try to run it through exec() from php. It creates a pdf file but it's not openable. So it seems like ghostscript is not working properly with imagemagick through php?
When I try to open a pdf image by creating a new imagick object ie:
$image = new imagick("passport.pdf");
This creates an error message like this:
Fatal error: Uncaught exception 'ImagickException' with message 'unable to create temporary file `passport.pdf': Permission denied @ error/pdf.c/ReadPDFImage/393' in /Users/hyun-hoshin/Documents/School_Work/Computing/Unit_4/Training/PHP/PHP_with_MySql_Beyond_the_Basics/Work/test.php on line 5
( ! ) ImagickException: unable to create temporary file `passport.pdf': Permission denied @ error/pdf.c/ReadPDFImage/393 in /Users/hyun-hoshin/Documents/School_Work/Computing/Unit_4/Training/PHP/PHP_with_MySql_Beyond_the_Basics/Work/test.php on line 5
It works fine for images though..
Do you have any Ideas?
EDIT!:
I've found the solution!!!
The problem was in the error message itself, it WAS a permissions error.
I found out that when image magick uses a delegate like ghost script, it needs to create a temporary file, and it either uses the default temporary file path TMPDIR or if you've set one, it uses MAGICK_TMPDIR. and I put in "set" in the command line, and the TMPDIR variable had the wrong permissions, as in it didn't allow any access to everyone, so it was just a simple case of changing those permissions so that apache could actually put in temporary files in to that directory.