Can't run Fred's texteffect script

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
mindstorm

Can't run Fred's texteffect script

Post by mindstorm »

I need a Linux guru. I'm running ImageMagick off a LAMP server (http://www.mindstorminteractive.com if anyone's curious about server details.) I uploaded Fred's texteffect script to a subdirectory (no file ext was added during download.)

ran

Code: Select all

<?php 
system("./texteffect -h",$return); 
echo $return;//126 
?>
. I assume running -h should normally echo a help menu of sorts. texteffect chmod was 775. server does not allow setting to 777:
"NOTE: File permissions higher than 775 will not work - "775" should be the highest. "777" specifically will not work - will result in an Internal Server Error - you should use 755 instead."
I then set chmod to 755, and ran the above script, which now returns a 0 and takes longer to process.
I also tried exec("./texteffect -h", $output, $return); and got same results both times.

Any thoughts are much appreciated.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Can't run Fred's texteffect script

Post by Bonzo »

This is what I had to do to run Freds scripts with php:
Download the script and upload it to your server.
Change the permissions to 755 on the script
Write your php code like this using the full path to the script
<?php
// Run the script
exec("/FULL PATH TO AUTOTRIM/autotrim.sh zelda3_border2w.png fred.png 2>&1", $array);
//Display any errors
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
When I ran the code I recived an error:
/autotrim.sh: line 271: bc: command not found
bc is a calculator that is built into Unix/Linux.

I ran this code to get some information about the path for bc and it did not return anything so I assumed bc was not installed.
I contacted my hosts who installed it and the code worked OK.

<?php
echo "<pre>";
system('which bc',$path); print_r($path);
echo "</pre>";
?>
I was also told that I may have been able to install the bc binarys ( although I could not find them ) and use the path to those in the code. I did not need to try that so I do not know if it would have worked or not.
Note the part about "full path to the script", this may be your problem.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Can't run Fred's texteffect script

Post by Bonzo »

I also renamed his script with an extension of .sh
mindstorm

Re: Can't run Fred's texteffect script

Post by mindstorm »

Still lost. I appended the .sh to the file, set chmod to 755, tried accessing it through absolute and relative paths (added $_SERVER['DOCUMENT_ROOT']) and got nothing.

the file is being found b/c file_get_contents and file_exists work. I just can't seem to execute it.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Can't run Fred's texteffect script

Post by Bonzo »

I have just noticed that you have no text or effects.

Code: Select all

<?php 
exec("PATH TO/texteffect.sh -t \"SOME PLAIN TEXT\" -s plain -e normal -f Arial -p 48 -c royalblue -b white -u lightpink ",$return); 
echo $return;//126 
?>
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Can't run Fred's texteffect script

Post by Bonzo »

Having a bad night - new PC that will not do what I want; having to reinstall the software I want etc. :(

Anyway this worked for me on my server:

Code: Select all

<?php

$array=array();
echo "<pre>";

exec("PATH TO/texteffect.sh -t \"SOME PLAIN TEXT\" -s plain -e normal -f bediz.ttf -p 48 -c royalblue -b white -u lightpink text.jpg 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";

?> 
<img src="text.jpg">
bediz.ttf was just a font I quickly found on the net and I uploaded it to the same directory as the php code and the texteffect.sh file.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't run Fred's texteffect script

Post by fmw42 »

Bonzo wrote:I have just noticed that you have no text or effects.

Code: Select all

<?php 
exec("PATH TO/texteffect.sh -t \"SOME PLAIN TEXT\" -s plain -e normal -f Arial -p 48 -c royalblue -b white -u lightpink ",$return); 
echo $return;//126 
?>

Bonzo,

He is just trying to get the help menu from the script (texteffect -h) and have it returned. That may be the issue. But I don't know how you get text returned from the script in PHP so that it can be viewed from the web page.

The help menu is being echoed to the terminal via a function call that involves unix sed

usage2()
{
echo >&2 ""
echo >&2 "$PROGNAME:" "$@"
sed >&2 -n '/^######/q; /^#/!q; s/^#*//; s/^ //; 4,$p' "$PROGDIR/$PROGNAME"
}

Is sed installed ?

Fred
Last edited by fmw42 on 2009-05-08T15:04:13-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't run Fred's texteffect script

Post by fmw42 »

mindstorm wrote:Still lost. I appended the .sh to the file, set chmod to 755, tried accessing it through absolute and relative paths (added $_SERVER['DOCUMENT_ROOT']) and got nothing.

the file is being found b/c file_get_contents and file_exists work. I just can't seem to execute it.

Have you tried supplying the full path manually rather than from some PHP call?

Fred
mindstorm

Re: Can't run Fred's texteffect script

Post by mindstorm »

Success! :D

pathing was not the issue, it's just that the -h cmd wasn't doing anything. I was able to make an image though:

Image

from this:

Code: Select all

<?php

$array=array();
echo "<pre>";

exec("./texteffect.sh -t \"SOME PLAIN TEXT\" -s outline -e pinch -d 0.9 -f Times-Roman -p 48 -c skyblue -b white -o black -l 1 -u lightpink text.jpg 2>&1", $array, $return);
echo "<br>".print_r($array)."<br>return =".$return;
echo "</pre>";

?>
<img src="text.jpg">
I also got these errors in the print_r:

Code: Select all

Array
(
    [0] => ./texteffect.sh: line 337: bc: command not found
    [1] => ./texteffect.sh: line 338: bc: command not found
    [2] => ./texteffect.sh: line 339: [: too many arguments
    [3] => ./texteffect.sh: line 252: bc: command not found
    [4] => ./texteffect.sh: line 253: [: -eq: unary operator expected
    [5] => ./texteffect.sh: line 327: bc: command not found
    [6] => ./texteffect.sh: line 328: [: -eq: unary operator expected
...
I requested the host install bc. Not sure what the other ones are about.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't run Fred's texteffect script

Post by fmw42 »

the others are likely errors because bc is not available and the values being returned are not compliant with what is expected by the conditional tests. You must be running on a Windows server, if you don't have bc available by default.
If so, see
http://www.imagemagick.org/Usage/windows/
and
http://studio.imagemagick.org/pipermail ... 22518.html
http://studio.imagemagick.org/pipermail ... 22522.html

see my note above about the -h option and returning text in PHP. perhaps Bonzo knows how to do that.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Can't run Fred's texteffect script

Post by Bonzo »

After a lot of trial and error this will display the help section:

Code: Select all

  $output = shell_exec("/FULL PATH TO/texteffect.sh -h 2>&1");
 echo "<pre>$output</pre><hr>";
Again I had to use the full path or else it didn't work.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Can't run Fred's texteffect script

Post by anthony »

If you ask, maybe Fred will replace the 'bc' dependence in the script with a method of using Imagemagick itself to do the mathematical calculations.

Actually it was Fred himself that came up with the idea of using FX escapes to do floating point mathematical calculations in scripts.

See IM Examples, FX escape expressions.
http://www.imagemagick.org/Usage/transform/#fx_escapes
Also usable in Windows DOS Scripts
http://www.imagemagick.org/Usage/windows/#calc_fx
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mindstorm

Re: Can't run Fred's texteffect script

Post by mindstorm »

I had the admin install bc and all the errors went away.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't run Fred's texteffect script

Post by fmw42 »

In a lot of my (older) scripts, I have used bc, especially if there are lots of calculations that need to be done in a loop. In many of my newer scripts, if timing is not an issue, I have replaced bc with the use of fx calculations to make the script pure IM commands where possible. In some scripts, even though I have replaced bc, I still need sed, tr, sort, wc, grep, expr, etc. So there may still be problems when running my scripts on Windows systems, possibly even with cygwin. Thus some of these unix features may need to be compiled with cycwin. I am not a Windows expert and so cannot say. If anyone has had experience with running my scripts under Windows/cygwin, perhaps they can comment what might be needed, besides bc.
brishtiteveja

Re: Can't run Fred's texteffect script

Post by brishtiteveja »

convert: unable to open image `./texteffect_0_717.miff': Permission denied. identify: unable to open image `./texteffect_0_717.miff': No such file or directory. identify: unable to open image `./texteffect_0_717.miff': No such file or directory. convert: invalid argument for option `x': -size. identify: unable to open image `./texteffect_0_717.miff': No such file or directory. identify: unable to open image `./texteffect_0_717.miff': No such file or directory. convert: unable to open image `./texteffect_0_717.miff': No such file or directory. convert: unrecognized option `-distort'. convert: unable to open image `./texteffect_0_717.miff': No such file or directory. convert: missing an image filename `text.jpg'. error

these are the errors i am seeing from my server.below is my code
<?php

$text="Hello";
exec("./texteffect.sh -t \" $text \" -s outline -e arc-top -a 60 -f arial.ttf -p 48 -c black -b yellow -o black -l 1 -u yellow text.jpg 2>&1",$h);
echo $h;

?>
<img src="text.jpg">

help me out.i am getting mad.
Post Reply