I have installed ImageMagick and GhostScript (Windows/IIS) and IM is working from the command line (specifically the convert command) so now I need to get it working in php. To that end I have the following code:
<?php
system("c:Program Files\ImageMagick-6.3.4-Q16\convert.exe c:\Inetpub\wwwroot\exp\graphics\imgMagick\test_file.ai c:\Inetpub\wwwroot\exp\graphics\imgMagick\AIC.png",$retvar);
echo $retvar; // Now you can check the $retvar for errors
?>
c:Program Files\ImageMagick-6.3.4-Q16\convert.exe - the root folder for IM, location of convert.exe
c:\Inetpub\wwwroot\exp\graphics\imgMagick\test_file.ai - the location of the target image to use for conversion
c:\Inetpub\wwwroot\exp\graphics\imgMagick\AIC.png - the location, name, and format for the converted image
Using the above code, it does not create a new png image. Before I set the permissions for the Internet Guest Account user to "read & execute" for the cmd.exe file located at C:\WINDOWS\system32, $retvar was echoing a value of -1. Once I set the permissions on C:\WINDOWS\system32\cmd.exe, $retvar is echoing a value of 1. In either case, the new graphic is NOT generated. Is there something wrong with my syntax? Any feedback will be greatly appreciated.
ImageMagick with php - system()
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: ImageMagick with php - system()
First, you are missing a backslash in the pathname for convert - you need C:\Program Files\....
If that doesn't help then perhaps the space in "Program Files" is causing the system call to see only "C:\Program" as the first argument. In which case try copying convert.exe up to C:\ and see if it works when you specify C:\convert.exe as the command pathname.
Pete
If that doesn't help then perhaps the space in "Program Files" is causing the system call to see only "C:\Program" as the first argument. In which case try copying convert.exe up to C:\ and see if it works when you specify C:\convert.exe as the command pathname.
Pete
Re: ImageMagick with php - system()
Thanks for the response. I moved the convert.exe file to C:\ but it had a return code of '0' and failed to convert the ai file to a png file. Here is the code I am using now:
<?php
exec("C:\convert.exe c:\Inetpub\wwwroot\exp\graphics\imgMagick\test_file.ai c:\Inetpub\wwwroot\exp\graphics\imgMagick\bb.png", $response, $return_code);
echo "<pre>";
// check status code. if successful
if ($return_code == 0) {
// process array line by line
foreach ($response as $line) {
echo "$line \n";
}
} else {
echo "Error in command"; // if unsuccessful display error
}
echo "</pre>";
?>
At this point I am not sure what to try. Any additional ideas will be much appreicated.
<?php
exec("C:\convert.exe c:\Inetpub\wwwroot\exp\graphics\imgMagick\test_file.ai c:\Inetpub\wwwroot\exp\graphics\imgMagick\bb.png", $response, $return_code);
echo "<pre>";
// check status code. if successful
if ($return_code == 0) {
// process array line by line
foreach ($response as $line) {
echo "$line \n";
}
} else {
echo "Error in command"; // if unsuccessful display error
}
echo "</pre>";
?>
At this point I am not sure what to try. Any additional ideas will be much appreicated.