Page 2 of 2
Re: Unable to execute ImageMagick command via PHP
Posted: 2008-11-08T15:21:35-07:00
by shafique
SOLVED!!!!!!
See the following link:
http://www.daniweb.com/forums/thread116143.html
And here's my solution (I uninstalled IM and reinstalled it into my home directory, that's why the paths are different from what I listed before. But this has nothing to do with what the problem was. I also changed the user from www to www2 - I added the www2 user and made a change in the httpd.conf file - but again this was part of troubleshooting and had nothing to do with the problem):
Code: Select all
putenv("MAGICK_HOME=" .$_ENV["MAGICK_HOME"]. "/Users/shafique/ImageMagick-6.4.5/");
exec('echo $MAGICK_HOME',$array);
putenv("PATH=" .$_ENV["PATH"]. "/Users/shafique/ImageMagick-6.4.5/bin");
exec('echo $PATH',$array);
putenv("DYLD_LIBRARY_PATH=" .$_ENV["DYLD_LIBRARY_PATH"]. "/Users/shafique/ImageMagick-6.4.5/lib");
exec('echo $DYLD_LIBRARY_PATH',$array);
echo "<br>".print_r($array)."<br>";
exec('/Users/shafique/ImageMagick-6.4.5/bin/convert /Users/www2/IMG_0041.JPG /Users/www2/41.png 2>&1', $array);
So the problem was that my environment variables would not stay set they way that I had set them after installing IM; I have to set them each time I run the php code, as above. Note that simply using:
Code: Select all
exec( 'export $DYLD_LIBRARY_PATH="/Users/shafique/ImageMagick-6.4.5/lib" ',$array);
(as per the IM installation instructions) will NOT work; the environment variable will NOT stay set this way (at least on my Leopard 10.5 MacBook Pro). Note also it necessary that both the input and output files be in a directory that is accessible to all (I did chmod a+rw /Users/www2).
I hope this helps others!
Re: Unable to execute ImageMagick command via PHP
Posted: 2009-07-31T01:52:17-07:00
by benny
I got exactly the same errors as you. And I did exactly as you did to solve it, but It will not work.
Someone please tell me how to do it.
shafique wrote:SOLVED!!!!!!
See the following link:
http://www.daniweb.com/forums/thread116143.html
And here's my solution (I uninstalled IM and reinstalled it into my home directory, that's why the paths are different from what I listed before. But this has nothing to do with what the problem was. I also changed the user from www to www2 - I added the www2 user and made a change in the httpd.conf file - but again this was part of troubleshooting and had nothing to do with the problem):
Code: Select all
putenv("MAGICK_HOME=" .$_ENV["MAGICK_HOME"]. "/Users/shafique/ImageMagick-6.4.5/");
exec('echo $MAGICK_HOME',$array);
putenv("PATH=" .$_ENV["PATH"]. "/Users/shafique/ImageMagick-6.4.5/bin");
exec('echo $PATH',$array);
putenv("DYLD_LIBRARY_PATH=" .$_ENV["DYLD_LIBRARY_PATH"]. "/Users/shafique/ImageMagick-6.4.5/lib");
exec('echo $DYLD_LIBRARY_PATH',$array);
echo "<br>".print_r($array)."<br>";
exec('/Users/shafique/ImageMagick-6.4.5/bin/convert /Users/www2/IMG_0041.JPG /Users/www2/41.png 2>&1', $array);
So the problem was that my environment variables would not stay set they way that I had set them after installing IM; I have to set them each time I run the php code, as above. Note that simply using:
Code: Select all
exec( 'export $DYLD_LIBRARY_PATH="/Users/shafique/ImageMagick-6.4.5/lib" ',$array);
(as per the IM installation instructions) will NOT work; the environment variable will NOT stay set this way (at least on my Leopard 10.5 MacBook Pro). Note also it necessary that both the input and output files be in a directory that is accessible to all (I did chmod a+rw /Users/www2).
I hope this helps others!
Re: Unable to execute ImageMagick command via PHP
Posted: 2009-08-06T19:49:52-07:00
by anthony
benny wrote:I got exactly the same errors as you. And I did exactly as you did to solve it, but It will not work.
Someone please tell me how to do it.
I am not a PHP user, but I am a UNIX expert, and the solution they giev is not quite correct..
This is what they should add to the top of PHP scripts..
Code: Select all
putenv("PATH=" . $_ENV["PATH"] . ":/opt/php5extras/ImageMagick/bin");
Of course change the directory to the right location for the 'convert' command!
Other techniques is to set a variable and use that to directly call the command using the full filename path.
Code: Select all
<?php
$im_path="/opt/php5extras/ImageMagick/bin"
header('Content-Type: text/plain');
system("exec 2>&1; $im_path/convert -version");
system("exec 2>&1; $im_path/convert -list type");
system("exec 2>&1; $im_path/convert -list font");
?>
See IM Examples, API's, PHP with command line API....
http://www.imagemagick.org/Usage/api/#php
Re: Unable to execute ImageMagick command via PHP
Posted: 2010-02-14T21:44:00-07:00
by Coyote6
Okay so I've been having a similar problem to the one people were having here but I had it working a couple days ago and then I did some updates and it no longer works.
So I tried the code:
Code: Select all
<?php
$array=array();
echo "<pre>";
exec("convert $original_img $new_img 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
Which "convert $original_img $new_img" was working before. Now I get command not found. So I changed the path to the actual file...
"/usr/local/ImageMagick/bin/convert $original_img $new_img"
And I get the error:
"dyld: unknown required load command 0x80000022"
I have no clue what this means.
The commands
"convert $original_img $new_img"
"/usr/local/ImageMagick/bin/convert $original_img $new_img"
both work via command line with a sudo command too or if I'm logged in as root.
Any help solving this is greatly appreciated. Thanks.
Re: Unable to execute ImageMagick command via PHP
Posted: 2010-02-14T21:55:11-07:00
by Coyote6
Oh and I'm on a MacBook running 10.5.8 and the updates were just regular updates.
Re: Unable to execute ImageMagick command via PHP
Posted: 2010-02-14T23:25:50-07:00
by Coyote6
Okay so I have found the problem (kinda). I had changed my /System/Library/LaunchDaemon/ for my apache server so it automatically starts. Now the original "convert $img $new_image" works when I manually start my apache server using the sudo command. So does anyone have any idea on why this is? I'm guessing it is something to do with the user permissions and who the apache server is running as. Thanks.
Re: Unable to execute ImageMagick command via PHP
Posted: 2010-07-08T10:21:24-07:00
by danux
Fixest this by recompiling with --with-frozenpaths. Works a treat in PHP.