THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.
I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.
IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.
echo "<pre>";
system("type convert");
echo "</pre>";
convert is /usr/local/bin/convert
Note: System displays the results to the screen where exec will not.
echo "<pre>";
system(\'which convert\',$path); print_r($path);
echo "</pre>";
/usr/local/bin/convert 0
'which' is a program that is generally on ALL UNIX machines, which searches the users command 'PATH' to find the given program.
'type' is a shell built in that does the same thing but just looks up the result from the saved results of the shells own search when it started up; it also returns builtins, alias and functions of that name that may be defined in the shell.
'locate' is a simular command that is available on more modern UNIX machines (typically Linux and MacOX) which just finds files (not commands) containing that name. It can also be useful for the above, but it will not always work on all OSs. It will find the 'convert' when it is NOT on the system supplied PATH to the PHP script.
To make the code more portable you can use this to get the path to convert from the server and automaticaly put it into your code.
// In my case $HTTP_ENV_VARS[\'PATH\'] = bin:usr/bin
$env_vars = explode( \':\', $HTTP_ENV_VARS[\'PATH\']);
// Combine the required part from $HTTP_ENV_VARS[\'PATH\'] and convert for your path.
$env_path = $env_vars[1]."/convert";
// Now $env_path = usr/bin/convert
// Usage:
exec("$env_path image.jpg -resize 100x100 output.jpg");
This is something I have found after a new install - for some reason none of the above give the path; where Imagemagick is installed is anyones guess.
I suggest you contact your hosts who should be able to tell you or if you have access to the server running # which convert should give the path. You could also try variations of /usr/local/bin/convert or /usr/bin/convert etc.