section31 Posted April 28, 2005 Posted April 28, 2005 (edited) I'm messing around with this on my personal windows box for fun and I can't seem to get ImageMagick Working. Has anyone ever installed imageMagick on a Windows Apache Server? I installed the binary, made sure it worked through the cmd prompt, then tried accessing it via a php script using one of those program execution functions like exec(), and the script doesn't do anything. No Errors, no warning, just continues with the rest of the script and stops. The exec function works just fine using other exe's in my windows/system32 directory, so I know its not that. Anyone have any ideas? NOTE: I've also posted this question on their forums, and I received not one reply Edited April 28, 2005 by section31 Quote
TweezerMan Posted April 28, 2005 Posted April 28, 2005 I have ImageMagick installed on my Windows machine with an Apache web server, but I've never tried to perform ImageMagick functions from PHP. Without seeing your script, it's hard to know what the problem could be. I did some searching on Google, and found something that might solve your problem though: Someone identified a problem with ImageMagick, Windows, and PHP's exec() function affecting Drupal: Imagemagick exec problem in WindowsThere is bug when running Drupal+Imagemagick in windows. PHP's Exec function does not work correctly in Windows then I have added exec wrapper that detects current mode and I Windows are detected then uses POpen. This code is taken from php.net exec function manual. ><?php function _image_exec($cmd) { if (substr(php_uname(), 0, 7) == "Windows"){ if ($h = popen("start \"bla\" $cmd", "r")) { pclose($h); return true; } else { return false; } } else { return exec($cmd); } } ?> If you want to try the above code, add the _image_exec() function code to the script you're trying to run and replace the call to exec() in your script with _image_exec(). Hope this helps... Quote
section31 Posted April 28, 2005 Author Posted April 28, 2005 (edited) Thanks for the reply, Well, I'm not running drupal, but I tried the function anyway and I got the same results. You wanted to know the exact script i was running. I started off really basic and simple , and like i said earlier I tried it on the cmd prompt first to see if it would work first and it did. ><? echo 'Begin <br />'; // I tried all the flavors of php's program execution functions, (backticks, system(), etc) exec('convert E:\Website\test.jpg -resize 50% E:\Website\new.jpg'); // I also changed the paths from absolute to relative, still nothing. echo '<br />Done<br />'; ?> Remeber, I also tried using other things in my system32 folder through exec and they all worked. For example, I tried ><? exec('ipconfig'); // This returned the correct stuff ?> So this negates the possibility that the exec functions are disabled or aren't working properly because safe mode is on or whatever. I just don't understand how image magick's forums can't answer one of the most fundamental question there is. How do I get image magick working through php with a windows apache box. Edited April 28, 2005 by section31 Quote
borfast Posted April 28, 2005 Posted April 28, 2005 Imagemagik is more used on *nix systems, so it's not that strange that there aren't many people in the forums knowing how to do that. I certainly don't, so I can't help you, sorry Quote
TweezerMan Posted April 28, 2005 Posted April 28, 2005 I tested your script on my system, and it appears to work. When I run it in my browser, a new image is created at the location I specified. The script displays nothing other than 'Begin' and 'Done' when the script executes, but the way you have it written, it shouldn't output anything. Remember, I also tried using other things in my system32 folder through exec and they all worked. For example, I tried ><? exec('ipconfig'); // This returned the correct stuff ?> I tested that on my system as well, and it returns nothing. According to the PHP manual: execExecute an external program (PHP 3, PHP 4 , PHP 5) string exec ( string command [, array &output [, int &return_var]] ) exec() executes the given command, however it does not output anything. It simply returns the last line from the result of the command. If the output argument is present, then the specified array will be filled with every line of output from the command. In order to display output from a command passed to exec(), you need to pass exec() an array variable to hold the lines of output, and if you want to see error messages, STDERR needs to be redirected to STDOUT. This will actually show the output of a command passed to exec() in my browser: ><?php $cmd = "ipconfig"; exec("$cmd 2>&1", $out); echo(join("<br />", $out)); ?> I'd suggest trying the following for your test script: ><?php echo 'Begin <br />'; $cmd = 'convert E:\Website\test.jpg -resize 50% E:\Website\new.jpg'; exec("$cmd 2>&1", $out, $err); if ($err) { echo('Error:<br />'); } else { echo('Command successfully executed.<br />'); } echo(join("<br />", $out)); echo '<br />Done<br />'; ?> Quote
TweezerMan Posted April 28, 2005 Posted April 28, 2005 Imagemagik is more used on *nix systems, so it's not that strange that there aren't many people in the forums knowing how to do that. <{POST_SNAPBACK}> My only experience with ImageMagick is in conjunction with Movable Type - MT uses ImageMagick to create image thumbnails. MT calls on ImageMagick functions through an ImageMagick perl module (sometimes referred to as PerlMagick), since MT is written in Perl. As long as everything else is installed correctly, ImageMagick works well on both *nix and Windows systems. Trying to call ImageMagick functions from PHP is a new one for me though. Quote
section31 Posted April 28, 2005 Author Posted April 28, 2005 I tested your script on my system, and it appears to work. When I run it in my browser, a new image is created at the location I specified. The script displays nothing other than 'Begin' and 'Done' when the script executes, but the way you have it written, it shouldn't output anything. hm, so it works on your machine huh. Forgot to mention, what version of php are you running, I'm running 5. Quote
section31 Posted April 28, 2005 Author Posted April 28, 2005 (edited) I'm running PHP 4.3.10 here. <{POST_SNAPBACK}> Ok, I just finished trying it with 4.3 and still no dice UPDATE: David, you're not going to believe this. Guess what I did to get it working. I restarted my computer... Why in the world did I need to restart my computer? Oh well, Thanks for all your help. Edited April 28, 2005 by section31 Quote
TweezerMan Posted April 28, 2005 Posted April 28, 2005 UPDATE: David, you're not going to believe this. Guess what I did to get it working. I restarted my computer... Why in the world did I need to restart my computer? <{POST_SNAPBACK}> I need to remember to suggest that. I've assisted a couple of people on the MT Forums with installing ImageMagick on their own Windows machines. I did not have to when I installed ImageMagick, but they said ImageMagick wouldn't work for them after installing it until after they had rebooted the machine. You're more than welcome for the help - I'm glad it's finally working for you! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.