PDF to JPG, ImageMagick, PHP and GS not playing nicely

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Rob Lang

PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Rob Lang »

I am trying to generate a jpg thumbnail image from the first page of a PDF. The error I get is:

Code: Select all

phMagick: Error executing "c:/progra~1/ImageMagick-6.5.6-Q16/convert "c:/inetpub/wwwroot/1km1kt/archive/equipmentindex7.pdf"[0] "c:/inetpub/wwwroot/1km1kt/archive/documents/destination.png""
return code: 1
command output :"convert: Postscript delegate failed `c:/inetpub/wwwroot/1km1kt/archive/equipmentindex7.pdf': No such file or directory @ pdf.c/ReadPDFImage/630.
convert: missing an image filename `c:/inetpub/wwwroot/1km1kt/archive/documents/destination.png' @ convert.c/ConvertImageCommand/2819."
My system set up is:
Windows XP SP 2 (win 32)
ImageMagic 6.5.6-Q16 (installed using win32 binary distribution)
GhostScript: gs815 (for win 32)
PHP 5

I am using phMagick to trap the errors, but if I use exec(), I get the same problem.

Investigation so far
1. PHP can execute. IUSER has access to cmd.exe.
2. Ghostscript is installed. I can see the entries in the registry (they point to the correct place) and if I use a third party viewer, I can view PDFs.
3. The command line works. If I take just the command line from inside the php exec() call, the image conversion works.
4. Configuration doesn't list any of the usual PS/GS/Postscript terms:

Code: Select all

C:\PROGRA~1\ImageMagick-6.5.6-Q16>convert -list configure

Path: C:\Program Files\ImageMagick-6.5.6-Q16\config\configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            vs8
COPYRIGHT     Copyright (C) 1999-2009 ImageMagick Studio LLC
DELEGATES     bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
HOST          windows-unknown-linux-gnu
LIB_VERSION   0x656
LIB_VERSION_NUMBER 6,5,6,1
NAME          ImageMagick
RELEASE_DATE  2009-09-15
VERSION       6.5.6
WEBSITE       http://www.imagemagick.org

Path: configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            vs8
COPYRIGHT     Copyright (C) 1999-2009 ImageMagick Studio LLC
DELEGATES     bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
HOST          windows-unknown-linux-gnu
LIB_VERSION   0x656
LIB_VERSION_NUMBER 6,5,6,1
NAME          ImageMagick
RELEASE_DATE  2009-09-15
VERSION       6.5.6
WEBSITE       http://www.imagemagick.org
5. Added Ghostscript to windows path Environment variable. No effect.
6. Checked ImageMagic delegate.xml config and the @PSDelegate@ entries are there.
7. Uninstalled imagemagic and ghostscript and then reinstalled in different orders. No effect.

What should be my next step? What am I doing wrong?

All help kindly received!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by magick »

Its possible Ghostscript does not like your PDF. Try a simple test. Does this work?
  • convert logo: logo.pdf
    convert logo.pdf logo.png
If that fails there is most likely a problem with your Ghostscript installation or ImageMagick is failing to identify the location of your Ghostscript installation.
Rob Lang

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Rob Lang »

Thanks for the quick reply, admin!

Yes, the command line does work. It generates a beautiful PNG from the first page. It seems to be the interaction with PHP that is failing.

How does the interaction change when PHP is involved? I would imagine that as soon as PHP executes convert.exe then it runs in its own process and has no bother with PHP anymore.

Are there any typical PHP pitfalls or debug information I could try? I'm going to investigate using a Process monitor next, I think.
Rob Lang

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Rob Lang »

Should I start looking elsewhere for a solution?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by magick »

Its not an uncommon problem, the PHP environment is different from the command line environment and sometimes environment variables must be injected in your script. Somewhere on the list someone mentioned injecting SystemRoot, however, we can't help because we're Linux / Mac experts and only use Windows if we're compelled to.
Rob Lang

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Rob Lang »

Thanks for your help nonetheless. It's good to know that I'm at least heading in the correct direction. :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by fmw42 »

I am no expert on this, but it looks to me like Ghostscript did not get installed at least not where IM knows about it as

DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib

does not list gs.

Try reinstalling GS and see if there are any error messages and find out where it gets installed.

Sorry if this is redundant or naive.
Rob Lang

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Rob Lang »

fmw42, I noticed that too. It certainly would explain a lot. I have reinstalled a few times. I might try an older version of GS and try again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by fmw42 »

Rob, I know little about Windows. but look carefully at the GS install for errors and other support libraries that it might need as well. I had that problem. Also be sure to find out where GS gets installed and make sure your IM install can find it. GS also requires some fonts to be installed and for you perhaps to tell IM in the configure where they are located. On my (Mac), I use the following ./configure

./configure --enable-delegate-build --enable-shared --disable-static \
--with-modules --with-quantum-depth=16 --with-gslib --without-wmf \
--enable-libtool-verbose --disable-dependency-tracking \
--with-gs-font-dir=/usr/local/share/ghostscript/fonts/ --with-lqr


See the last line for --with-gs-font-dir


Fred
Rob Lang

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Rob Lang »

Hi Fred,
Thanks for the extra thought. I'll write all these things up when I'm done. I'll give reconfiguring IM again and see if that fixes it. The delegant not showing up in the config list makes me wonder if modern versions of GS aren't installed under the same registry keys as they used to be. Therefore, when IM looks in the registry for the existence of GS, it can't find it.
Wittner

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Wittner »

Hi,

I'm having the same problem. Did you resolve this and if so, how?

cheers,

Wittner
Rob Lang

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by Rob Lang »

Hi Wittner,
No, I didn't find a solution to it yet. I tried the configure command but that didn't work - probably because it is a Unix one. I am pretty sure that reconfiguring ImageMagick to be able to use Ghostscript is the answer but cannot find out how to configure the beast.

This means that my development work has to be performed by uploading to a secret place on the Unix staging server - on which it is installed ok. I'd much rather have it working on my Dev box though.

Do you have any other ideas?
martinw17
Posts: 39
Joined: 2006-09-07T02:10:27-07:00
Location: Brighton, UK

Re: PDF to JPG, ImageMagick, PHP and GS not playing nicely

Post by martinw17 »

Do you see any errors in the PHP logs, for example failure to load the Ghostscript dll? I don't know much about PHP but if IM can find GS when you run it from the command line (outside PHP) then it looks like IM knows where GS is - so perhaps the process that's running IM from PHP doesn't have permission to load the GS dll.
Sorry I can't be of more help!
Regards,
Martin
Post Reply