Page 1 of 1

SOLVED - Weird problem with +polaroid in exec()

Posted: 2009-05-06T14:09:27-07:00
by rick0
Hi All,

I've been struggling with something really weird for the last couple of hours. Let me expalin.

I try to run this cmd in a PHP script:
exec ("convert test.jpg -background black +polaroid -background white -flatten test2.jpg");
RESULT: Doesn't work. test2.jpg is not created. Tried "convert test.jpg +polaroid test2.png" but no result either.

I then try to run the cmd convert test.jpg -background black +polaroid -background white -flatten test2.jpg from a root shell on my server.
RESULT: It works perfectly and the file test2.jpg is created.

Then I try to troubleshoot my PHP script to see where it goes wrong.
I try to exec the cmd without the +polaroid: exec ("convert test.jpg -background black -flatten test2.jpg");
RESULT: works perfectly and test2.jpg is created.

NOTE:After some more testing, I found out that the cmd -sketch doesnt work either from exec() within php.
but works fine from root shell...

Can anybody explain me why, when I have +polaroid in my exec cmd it doesnt work ?
Version supports polaroid because I tried from a root shell and all fine...

Thanks for the help on this crazy problem.

Re: Weird problem with +polaroid in exec()

Posted: 2009-05-06T16:21:25-07:00
by fmw42
You need to know the full path to convert. It is usually

/usr/local/bin/convert

or

/usr/bin/convert


You can test using:

<?php
system("/usr/local/bin/convert -version");
?>


or

<?php
$IM_version=shell_exec("/usr/local/bin/convert -version");
echo $IM_version
?>

or

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

Re: Weird problem with +polaroid in exec()

Posted: 2009-05-06T16:53:36-07:00
by anthony
Their are a number of things that could go wrong for PHP.

The first thing to do is try and get the errors that may have resulted from the exec call. Either from the Web server logs (often difficult to do) or capture it in some way.

As for reasons, the main fault in that the environment is different when run under PHP. It may run as a different user, with less access permissions and a completely different setup and initialization.

This means,
  • The command is not in the comand PATH, and thus you may need the full path to the command (Fred touched on this above)
  • You may not be in the same directory as the script or the web page that lauched the PHP script
  • The directory may not be writeable (why are you writing to the directory anyway?)
  • other environment variables may not be correct, like HOME, LD_LIBRARY_PATH, MAGICK_TEMPDIR, etc.
Most of these problem however can be worked out simply by finding some way of getting error messages from your PHP script.

Re: SOLVED - Weird problem with +polaroid in exec()

Posted: 2009-05-07T04:53:21-07:00
by rick0
Thanks for the prompt replies Anthony & Fred!
You guys are very helpful!

I tried what fred sugested:
shell_exec("/usr/local/bin/convert -version"); - OK
then ... exec("/usr/local/bin/convert FULLPATH/test.jpg -background black +polaroid -background white -flatten FULLPATH/test2.jpg") - OK

and it worked fine!


So let me explain for the people that might on day have the same issue.
I was using exec("convert THEN CMD INFO YOU WANT") - which is not correct BUT does work for me for any cmd except +polaroid & +sketch

What you should do is use ONLY the full path like this: exec("/usr/local/bin/convert THEN CMD INFO YOU WANT")

Thats it folks.

Thanks for the help!!
Best forum on the net! ;)