Jump to content

ImageMagick and Executing External Programs in PHP


Jip

Recommended Posts

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.

I think you have to escape the \

 

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

 

Like seen above.

Frost110 - thanks for the feedback. Unfortunately, this did not work. I also tried moving the convert.exe to the root of C: since C:\Program Files contains a space. However, this did not work either. Here is my updated code that looks for a return code to determine the outcome:

 

<?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>";

?>

 

Not sure what to try next so any additional feedback w/b appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.