Weird Errors with PDFs.

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
h2shin
Posts: 7
Joined: 2012-09-03T10:28:44-07:00
Authentication code: 67789

Weird Errors with PDFs.

Post 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.
Last edited by h2shin on 2012-09-04T02:49:43-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird Errors with PDFs.

Post 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.
h2shin
Posts: 7
Joined: 2012-09-03T10:28:44-07:00
Authentication code: 67789

Re: Weird Errors with PDFs.

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird Errors with PDFs.

Post by fmw42 »

My best guess is that PHP cannot find GS. But that is only a guess.
h2shin
Posts: 7
Joined: 2012-09-03T10:28:44-07:00
Authentication code: 67789

Re: Weird Errors with PDFs.

Post by h2shin »

any ideas as to how to fix this?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird Errors with PDFs.

Post 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
h2shin
Posts: 7
Joined: 2012-09-03T10:28:44-07:00
Authentication code: 67789

Re: Weird Errors with PDFs.

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird Errors with PDFs.

Post 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.
Post Reply