how php loop in exec ?
-
- Posts: 44
- Joined: 2014-11-28T16:19:41-07:00
- Authentication code: 6789
how php loop in exec ?
Hi,
i have this code for example:
exec("for (($i=1; i<=$5; $i++)); do convert -size 1024x -font tahoma.ttf -pointsize 42 -channel RGBA -background transparent -fill dodgerblue1 -stroke slategray4 caption:'Hi, this is a text' intro$i.png; done");
but didn't work,
is it possible do while or for loop in exec?
how can ++ the counter?
thank you
i have this code for example:
exec("for (($i=1; i<=$5; $i++)); do convert -size 1024x -font tahoma.ttf -pointsize 42 -channel RGBA -background transparent -fill dodgerblue1 -stroke slategray4 caption:'Hi, this is a text' intro$i.png; done");
but didn't work,
is it possible do while or for loop in exec?
how can ++ the counter?
thank you
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how php loop in exec ?
I suspect you need to write the loop part in PHP and then call just the convert part in exec(). see http://php.net/manual/en/control-structures.for.php
-
- Posts: 44
- Joined: 2014-11-28T16:19:41-07:00
- Authentication code: 6789
Re: how php loop in exec ?
dear fred, i need to create some png file such as : 1.png, 2.png,3.png and etc. for example or draw some text or ...
i think i need create loop inside exec() function, like:
cat text_data.txt |
while read width gravity color pointsize x y text
do
convert -size ${width}x -gravity $gravity -fill $color -background wheat \
-pointsize $pointsize -page +${x}+${y} label:"${text}" miff:-
done |
convert -size 200x100 xc: - -flatten text_layered.jpg
but, with this syntax, php do not anything but create 200*100 text_layered.jpg,
what is the true coding with php and exec?
i think i need create loop inside exec() function, like:
cat text_data.txt |
while read width gravity color pointsize x y text
do
convert -size ${width}x -gravity $gravity -fill $color -background wheat \
-pointsize $pointsize -page +${x}+${y} label:"${text}" miff:-
done |
convert -size 200x100 xc: - -flatten text_layered.jpg
but, with this syntax, php do not anything but create 200*100 text_layered.jpg,
what is the true coding with php and exec?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how php loop in exec ?
I am not a PHP expert, but I think you need to use PHP commands to do the looping with a for loop or other PHP loop methods. Then inside the loop, you can use exec() to process the image. I do not know if PHP exec() even accepts pipes.
Alternately, create a unix bash shell script to do all your commands above and just use PHP exec() to call the shell script.
Do your commands above work properly in a terminal without PHP? I would make sure they work before porting to PHP.
Alternately, create a unix bash shell script to do all your commands above and just use PHP exec() to call the shell script.
Do your commands above work properly in a terminal without PHP? I would make sure they work before porting to PHP.
-
- Posts: 44
- Joined: 2014-11-28T16:19:41-07:00
- Authentication code: 6789
Re: how php loop in exec ?
i never use terminal and shell script, i need use that with php, in imagemagick command, pipes dosen't work.
Re: how php loop in exec ?
exec () is calling an external program and will accept variables but I do not think you can have the loop inside the exec(). You would need to go to a forum which deals with php like the sitepoint or stackoverflow forums to find out more.
You would need to do something like:
But again this is a php question and not an Imagemagick one.
You would need to do something like:
Code: Select all
for ($i=1; $i<=5; $i++){
exec("convert -size 1024x -font tahoma.ttf -pointsize 42 -channel RGBA -background transparent -fill dodgerblue1 -stroke slategray4 caption:'Hi, this is a text' intro$i.png");
}
-
- Posts: 44
- Joined: 2014-11-28T16:19:41-07:00
- Authentication code: 6789
Re: how php loop in exec ?
thank you bonzo, work for me,
i open this topic to find a way to use loop in exec() witch use in php for imagemagick mostly.
i open this topic to find a way to use loop in exec() witch use in php for imagemagick mostly.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how php loop in exec ?
As I said above, take your commands and put them into a bash shell script. It is just a text file with the first line containing
#!/bin/bash
Then call the script in exec(). See Bonzo's web site at
http://www.rubblewebs.co.uk/index.php
http://www.rubblewebs.co.uk/imagemagick ... l_bash.php
This question is not really an Imagemagick question, but one for Unix shell scripting forums.
You really should learn to use the terminal to test your IM command lines before putting them into PHP. If it has an error, it is easier to detect in the terminal. Furthermore, if you run your commands in PHP exec(), you won't know if a problem is with PHP or Imagemagick or with your unix portions of the code.
To use the terminal, just copy and paste your code and hit return.
#!/bin/bash
Then call the script in exec(). See Bonzo's web site at
http://www.rubblewebs.co.uk/index.php
http://www.rubblewebs.co.uk/imagemagick ... l_bash.php
This question is not really an Imagemagick question, but one for Unix shell scripting forums.
You really should learn to use the terminal to test your IM command lines before putting them into PHP. If it has an error, it is easier to detect in the terminal. Furthermore, if you run your commands in PHP exec(), you won't know if a problem is with PHP or Imagemagick or with your unix portions of the code.
To use the terminal, just copy and paste your code and hit return.
-
- Posts: 44
- Joined: 2014-11-28T16:19:41-07:00
- Authentication code: 6789
Re: how php loop in exec ?
thank you fred, i got it, and i will try to use terminal.
-
- Posts: 44
- Joined: 2014-11-28T16:19:41-07:00
- Authentication code: 6789
Re: how php loop in exec ?
Hi, i ask in stackoverflow about loop in exec and there is a solution for that:
http://stackoverflow.com/questions/2731 ... 5#27311115
http://stackoverflow.com/questions/2731 ... 5#27311115
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how php loop in exec ?
That is similar to what I told you earlier. Use PHP looping.
-
- Posts: 44
- Joined: 2014-11-28T16:19:41-07:00
- Authentication code: 6789
Re: how php loop in exec ?
Yes fred. thank you again.