Connecting Tech Pros Worldwide Forums | Help | Site Map

Php and ImageMagick in Windows?

Chuck Anderson
Guest
 
Posts: n/a
#1: Jul 17 '05
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
C:\apache\htdocs\testing\temp_.png

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).

TIA

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

Chris Hope
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Php and ImageMagick in Windows?


Chuck Anderson wrote:
[color=blue]
> 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
> C:\apache\htdocs\testing\temp_.png
>
> 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).[/color]

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

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Php and ImageMagick in Windows?


"Chuck Anderson" <websiteaddress@seemy.sig> wrote in message
news:jLOdnc7uXt4DpPHfRVn-oQ@comcast.com...[color=blue]
> 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
> C:\apache\htdocs\testing\temp_.png
>
> 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);[/color]

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


Chuck Anderson
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Php and ImageMagick in Windows?


Chung Leong wrote:
[color=blue]
>"Chuck Anderson" <websiteaddress@seemy.sig> wrote in message
>news:jLOdnc7uXt4DpPHfRVn-oQ@comcast.com...
>
>[color=green]
>>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
>>C:\apache\htdocs\testing\temp_.png
>>
>>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);
>>
>>[/color]
>
>You know you need to escape backslashes in strings, right?
>
>[/color]
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
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Closed Thread