Php and ImageMagick in Windows?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am trying to use ImageMagick from a Php script running under Windows XP.

I have installed the latest version of ImageMagick - 6.2.1-7 and even
tried backing up to version 5.5.7 (based on a recommendation I found
during a Google search), but I can not get ImageMagick to work in Php
(using exec or system).

ImageMagick works from a Windows Command prompt -

e.g., convert C:\apache\htdocs\testing\temp_.jpg

but that same command using the system function -

i.e., system("convert C:\apache\htdocs\testing\temp_.jpg
C:\apache\htdocs\testing\temp_.png", $retval);

always fails with a retval of either 4 or 1.  (The retval was 4 until I
rebooted and tried again, and now it is always 1).

I am able to execute other windows commands (e.g. dir) from within the
system and exec functions in Php.

Can anyone help me figure out how to get ImageMagick to run from a Php
script - in Windows?  I have tired using the full path to the convert
command, but that does not change anything (the ImageMagick installation
adds itself to the PATH environment variable anyway).


 Chuck Anderson • Boulder, CO
 Integrity is obvious.
 The lack of it is common.

Re: Php and ImageMagick in Windows?

Quoted text here. Click to load it

You know you need to escape backslashes in strings, right?

Re: Php and ImageMagick in Windows?

Chung Leong wrote:

Quoted text here. Click to load it
Thanks for the replies. I must admit that I was being a little ignorant
on that count ... but, I had already tried reversing the slashes:

system("convert.exe C:/apache/htdocs/testing/temp_.jpg
C:/apache/htdocs/testing/temp_.png", $retval);

and after these two replies, I tried escaping the backslashes:

system("convert.exe C:\apache\htdocs\testing\temp_.jpg
C:\apache\htdocs\testing\temp_.png", $retval);

But both methods still gave me a retval of 1.

However, I then tried using a relative path - or no path (leave off the c:):

system("convert.exe temp_.jpg temp_.png", $retval);

or (placing the images in a sub folder)

system("convert.exe photos/temp_.jpg photos/temp_.png", $retval);

and then it it works.

It seems that I can not use an absolute path
(c:\apache\htdocs\testing\temp_.png). I'm not sure why the c: part is a
problem, but using relative paths is all I really need to do. I was only
using full paths to be sure I was pointing to the right location of the
files while testing.

Thanks for the help.

 Chuck Anderson Boulder, CO
 Integrity is obvious.
 The lack of it is common.

Re: Php and ImageMagick in Windows?

Chuck Anderson wrote:

Quoted text here. Click to load it

You probably need to escape the \ characters, or switch them around so
they're / instead.

Chris Hope | |

Site Timeline