Page 1 of 1

Weird Errors with PDFs.

Posted: 2012-09-03T10:33:32-07:00
by h2shin
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.

Re: Weird Errors with PDFs.

Posted: 2012-09-03T10:43:52-07:00
by fmw42
I am no expert on this, but it looks like a PHP permission problem possibly with the file or folder where it is going. The other more likely possibility is that PHP does not know where ghostscript resides or where the ghostscript fonts reside. But I cannot tell you how to check or tell it where. Have you checked your phpinfo.php file?

Perhaps your PHP commands are not correct. I think you may have to create a placeholder without the name. Then create the file and then save it to a name. Look at http://www.rubblewebs.co.uk/index.php for IM with PHP.

Re: Weird Errors with PDFs.

Posted: 2012-09-03T12:05:15-07:00
by h2shin
fmw42 wrote:I am no expert on this, but it looks like a PHP permission problem possibly with the file or folder where it is going. The other more likely possibility is that PHP does not know where ghostscript resides or where the ghostscript fonts reside. But I cannot tell you how to check or tell it where. Have you checked your phpinfo.php file?

Perhaps your PHP commands are not correct. I think you may have to create a placeholder without the name. Then create the file and then save it to a name. Look at http://www.rubblewebs.co.uk/index.php for IM with PHP.
The folder and the image both belong to www, so I don't think it's the permissions.
I've checked the phpinfo, and under imagick, it lists pdf as one of the supported formats.
Outside of php, imagemagick works fine with ghostscript, in terminal...
I really don't know what the problem is, I can only assume it's ghostscript because everything else works fine with imagick.

and $image=new imagick("something.jpg") works, just a pdf file that doesn't work...

It's just confusing since it's says unable to create temporary file, permission denied at ReadPDFImage.393 and I'm not sure if it's a permissions problem, since just doing exec() function for convert doesn't work either for pdfs.

Re: Weird Errors with PDFs.

Posted: 2012-09-03T12:23:27-07:00
by fmw42
My best guess is that PHP cannot find GS. But that is only a guess.

Re: Weird Errors with PDFs.

Posted: 2012-09-03T13:13:01-07:00
by h2shin
any ideas as to how to fix this?

Re: Weird Errors with PDFs.

Posted: 2012-09-03T14:00:59-07:00
by fmw42
h2shin wrote:any ideas as to how to fix this?

sorry, no. you might search the archives and see if you can find any clues

Re: Weird Errors with PDFs.

Posted: 2012-09-04T02:48:08-07:00
by h2shin
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.

:D

Re: Weird Errors with PDFs.

Posted: 2012-09-04T09:59:08-07:00
by fmw42
h2shin wrote: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.

:D

Thanks for replying with the solution. Something to know for the future if others have the same issue.