Jump to content

Recommended Posts

Posted (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 :P :thumbup1:

Edited by section31
Posted

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 Windows

There 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...

Posted (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. :thumbup1:

Edited by section31
Posted

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 :notworthy:

Posted

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:
exec

Execute 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 />';
?>

Posted
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.

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. :eek:

Posted
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.

Posted (edited)
I'm running PHP 4.3.10 here.

Ok, I just finished trying it with 4.3 and still no dice :whip:

 

 

UPDATE: David, you're not going to believe this. Guess what I did to get it working. I restarted my computer... rofl.gif Why in the world did I need to restart my computer?

 

Oh well, Thanks for all your help.

Edited by section31
Posted
UPDATE: David, you're not going to believe this.  Guess what I did to get it working.  I restarted my computer...  rofl.gif  Why in the world did I need to restart my computer? 

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! :whip:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...