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.
SOLVED - Weird problem with +polaroid in exec()
SOLVED - Weird problem with +polaroid in exec()
Last edited by rick0 on 2009-05-07T04:36:54-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Weird problem with +polaroid in exec()
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]);
?>
/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]);
?>
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Weird problem with +polaroid in exec()
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 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: SOLVED - Weird problem with +polaroid in exec()
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!
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!