How to run Fred's ImageMagick Scripts in PHP under Windows?

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
MrDark
Posts: 2
Joined: 2012-11-21T11:51:36-07:00
Authentication code: 6789

How to run Fred's ImageMagick Scripts in PHP under Windows?

Post by MrDark »

Hi!

I'm a totally new user of ImageMagick.
So please be patient with my lack of knowledge!

I am trying to eventually get a Fred's ImageMagick Script to process a big batch of images using PHP under XAMPP in a Windows environment.

I have managed to get ImageMagic to perform this commands successfully:

Code: Select all

<?php 
header("Content-Type: text/plain"); 
system("convert -version"); 
?>
and

Code: Select all

<?php 
exec("convert inimg/IMG_2247.JPG -thumbnail 100x100 outimg/IMG_2247.png");
?>
But I can not get Fred's ImageMagick Script aspectpad to work
I have downloaded the aspectpad script and placed it in htdocs folder.
http://www.fmwconcepts.com/imagemagick/ ... /index.php

When I try to perform the following commands

Code: Select all

<?php 
$result = exec("aspectpad -a 1 -m l inimg/IMG_2248.JPG outimg/IMG_2248.png 2>&1"); 
echo $result;
?> 
I get this output:
aspectpad is not an internal or external command

I'm stuck! Please help me!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by fmw42 »

try

<?php
$result = exec("fullpath2/aspectpad -a 1 -m l inimg/IMG_2248.JPG outimg/IMG_2248.png 2>&1");
echo $result;
?>

or

<?php
$result = exec("bash fullpath2/aspectpad -a 1 -m l inimg/IMG_2248.JPG outimg/IMG_2248.png 2>&1");
echo $result;
?>

If the above does not work, then see my home page for Pointers when using PHP.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by Bonzo »

I do not think you can run them under XAMMP on windows as some required commands are not part of the windows software and not includded in XAMMP.

I think people have run them when Cgwyn or whatever it is called was installed.

Out of interest on a server with php I need to use the full path to aspectpad and CHMOD it to 777
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by fmw42 »

I believe what Bonzo meant was that you cannot run it on Windows native without PHP. But with PHP, it should work, though he knows best. But his point about making the script executable may also be one of your issues. chmod u+x aspectpad. Also be sure that the file has its suffix removed or if it is really .sh, then add .sh to the script name in your command and when making it exectuable.



<?php
$result = exec("fullpath2/aspectpad.sh -a 1 -m l inimg/IMG_2248.JPG outimg/IMG_2248.png 2>&1");
echo $result;
?>
MrDark
Posts: 2
Joined: 2012-11-21T11:51:36-07:00
Authentication code: 6789

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by MrDark »

Thanks both for your help!

i used this PHP script to perform the command chmod u+x aspectpad in a windows environment.

Code: Select all

 <?php 
$result = chmod("aspectpad", 0777); 
echo $result;
?> 
Is that enough?

I get a 1 in return indicating that the command was successful.
I also tried to change the code to
chmod("aspectpadxxx", 0777);
resulting in the following error message:
Warning: chmod(): No such file or directory in D:\xampp\htdocs\chmod.php on line 2

So I know that the path to aspectpad is correct.
Somehow I cannot get aspectpad to be an executable in windows.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by fmw42 »

Sorry I am not a Windows user. Bonzo, perhaps, can help with file permissions on Windoows.

Can you find where you put the file? If so, right click on the file and select the preferences for the file and see if you can change them in the preferences window that opens. Otherwise, hopefully Bonzo or some other Windows user can help.

Did you try adding the full path to the script as per


<?php
$result = exec("fullpath2/aspectpad.sh -a 1 -m l inimg/IMG_2248.JPG outimg/IMG_2248.png 2>&1");
echo $result;
?>

with or without the .sh
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by whugemann »

I remember that I once tested one of Fred's scripts under Windows, but I cannot find the corresponding thread on this forum. Anyway, my experience with it resulted in my remarks at http://www.imagemagick.org/Usage/windows/#cygwin, so I would rather try what's written there, instead of dealing with XXAMP & Co. Seem's like you're almost done after the installation of Cygwin.
Wolfgang Hugemann
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by Bonzo »

Thats interesting whugemann; I could never even get a bash file running on XAMMP.

I posted on another forum about it and the concensus was that it was not possible mostly due to functions and external programs that are not available on Windows by default.

One user here said he had a bash file running under XAMMP but I could not reproduce his method; but then he had cgwyn installed.
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by whugemann »

Just to clarify terms:

I spoke of cygwin, which is a complete Unix bash shell under Windows (well, at least kind of, I hope).

XAMMP, however, is a special WAMP (= Windows + Apache + MySQL + PHP), which is something different. In this environment, PHP cannot rely on certain Unix functionalities to be present and this may indeed cause problems with certain scripts that rely on Unix functionality.
Wolfgang Hugemann
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to run Fred's ImageMagick Scripts in PHP under Windo

Post by Bonzo »

That is what I was saying as well in a round about way.
Post Reply