Page 3 of 4
Re: Uniting different commands in a single one
Posted: 2010-12-10T13:49:42-07:00
by javismiles
i wonder if there is a different solution using pipes or something to still in 1 command, first generate all the texts with justification and then pipe them
all together into the final large canvas, but doing that in two parts united by pipes so that the justification doesnt interfere with the second part
Re: Uniting different commands in a single one
Posted: 2010-12-10T14:02:57-07:00
by Bonzo
I have tried this with the same result:
Code: Select all
<?php
$cmd = " -size 2040x2856 xc:none ( -background none -fill #ff33cc -font Arial -pointsize 60 -gravity west label:\"hello\\nhow are you\" -write mpr:image1 +delete ) ".
" ( -background none -fill #ff55cc -font Arial -pointsize 40 -gravity east label:\"hello\\nhow are you\" -write mpr:image2 +delete ) ".
" ( -background none -fill #ff11cc -font Arial -pointsize 20 -gravity center label:\"hello\\nhow are you\" -write mpr:image3 +delete ) ".
" mpr:image1 -gravity northwest -geometry +438+114 -composite mpr:image2 -gravity northwest -geometry +840+342 -composite mpr:image3 -gravity northwest -geometry +1040+1.342 -composite -quality 95";
exec(" convert $cmd finalresultingimage.png ");
?>
What is needed is some sort of "reset code" for the position.
Re: Uniting different commands in a single one
Posted: 2010-12-10T14:05:08-07:00
by javismiles
that is a great try you did there, its amazing
that still like that it doesnt work, seems like in the moment we create a large canvas in first step, all what comes after is interpreted relative
to that large canvas, is there any way to create the large canvas on the last step instead of the first? maybe then could work
---------------------------------
<?php
$cmd = " -size 2040x2856 xc:none ( -background none -fill #ff33cc -font Arial -pointsize 60 -gravity west label:\"hello\\nhow are you\" -write mpr:image1 +delete ) ".
" ( -background none -fill #ff55cc -font Arial -pointsize 40 -gravity east label:\"hello\\nhow are you\" -write mpr:image2 +delete ) ".
" ( -background none -fill #ff11cc -font Arial -pointsize 20 -gravity center label:\"hello\\nhow are you\" -write mpr:image3 +delete ) ".
" mpr:image1 -gravity northwest -geometry +438+114 -composite mpr:image2 -gravity northwest -geometry +840+342 -composite mpr:image3 -gravity northwest -geometry +1040+1.342 -composite -quality 95";
exec(" convert $cmd finalresultingimage.png ");
Re: Uniting different commands in a single one
Posted: 2010-12-10T14:20:56-07:00
by Bonzo
I am wondering if there is a layer or page method of doing this but we will have to wait and see if someone else comes up with an idea.
This didn't work either:
Code: Select all
<?php
$cmd = " -size 2040x2856 xc:none ( -size 2040x2856 xc:none -background none -fill #ff33cc -font Arial -pointsize 60 -gravity west label:\"hello\\nhow are you\" -geometry +438+114 -composite -write mpr:image1 +delete ) ".
" ( -size 2040x2856 xc:none -background none -fill #ff55cc -font Arial -pointsize 40 -gravity east label:\"hello\\nhow are you\" -geometry +840+342 -composite -write mpr:image2 +delete ) ".
" ( -size 2040x2856 xc:none -background none -fill #ff11cc -font Arial -pointsize 20 -gravity center label:\"hello\\nhow are you\" -geometry +1040+1.342 -composite -write mpr:image3 +delete ) ".
" mpr:image1 -composite mpr:image2 -composite mpr:image3 -composite -quality 95";
exec(" convert $cmd finalresultingimage.png ");
?>
Re: Uniting different commands in a single one
Posted: 2010-12-10T14:25:30-07:00
by javismiles
i agree yess,
i guess there is no way to move the -geometry positioning + canvas 2040x2880 definition to the very end of the command,
or maybe there is another type of command as you say
Re: Uniting different commands in a single one
Posted: 2010-12-10T14:47:11-07:00
by javismiles
hey Bonzo, just wanted to say thank you for trying all these versions, that was
really nice of you
let's see if anybody else can tell us if there is anything else left to try to make justification independent of the large canvas within a single command
thank you again
jav
Re: Uniting different commands in a single one
Posted: 2010-12-10T18:20:05-07:00
by anthony
It sounds like you are trying to fill in a form image with text labels!!!!!
Okay paradigm shift, that will work better with a script processing label positions and justifications from some data file...
Input data file: Fields are: width gravity color pointsize x y text
Code: Select all
180 west red 10 10 10 This is left aligned
120 east green 12 30 40 right aligned
140 center blue 16 50 70 centered text
You can download the above from
http://dl.dropbox.com/u/9500683/text_data.txt
NOTE only the last field can be multiple words when using shell "read"
Code: Select all
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.png
Note I used a "wheat" background for the labels so that you can see the 'field' that it is filling. Replace it with 'none' for transparency. You can use "caption:" instead for word wrapped field filling. and add extra fields as you need them.
The above is all PIPELINED, and uses "miff:" as the image format in the pipeline as you can just concatenate miff images together to generate a multi-image file (or pipelined stream in this case). No intermediate images, Just text data in image out.
You can use multiple input files too. For example read the text field locations fromone file, and the text to fill in from another file.
However the shell scripting is a little more complex involving
shell file descriptors, so you can read from multiple files in the main loop. That however is purely shell programming and not imagemagick!
I have uploaded this example in IM Examples, Text Handling, Form Filling
http://www.imagemagick.org/Usage/text/#form_filling
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:07:09-07:00
by javismiles
hey Anthony, thank you very much for all of that, thats fantastic,
im going to try it out
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:14:49-07:00
by javismiles
yes i will try to pass to php your code
i can just take the data from my array instead of from the text file so thats all good,
i will try thank you Anthony!
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.png
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:18:19-07:00
by anthony
In PHP you should be able to pipe in the text data into the while loop using some sort of open to command function.
I am not familiar with PHP but it should be available.
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:19:42-07:00
by javismiles
actually i have doubts how to pass this to php,
that miff:- output, will it hold in a for php loop?
and the final convert outside the loop will that connect with the previous ones when all is done
in php instead of in the command line?
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.png
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:22:18-07:00
by anthony
It should hold as PHP runs the command in a Sub-shell. It is the pipe you need to worry about, not the miff:-
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:25:14-07:00
by javismiles
would it be like this in php?
that width you had at the beginning not sure what it was for
(its all hardcoded for demo)
for ($i=1; $i<$number_texts;$i++)
{
$command.=' convert -gravity west -fill #337766 -background none -pointsize 100 -page +100+100 label:"hello\nmyfriend" miff:- done convert -size 2000x3000 xc: -flatten final.png';
passthru($command);
}
i guess its not like that, im just not sure how to integrate in php the pipe, and how to connect the loop to the pipe to the last of your sentences on 1 single thing in php
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:32:27-07:00
by anthony
NO.
More like..
Code: Select all
open( CMD, '| while read .... done | convert ... image_result.png' );
for ($i=1; $i<$number_texts;$i++) {
...
print CMD "$width $gravity .... $text\n";
...
}
close(CMD)
Note that the above looks more like perl which I am familiar with, rather than PHP. I just don't know PHP enough.
Re: Uniting different commands in a single one
Posted: 2010-12-10T19:39:36-07:00
by javismiles
uuuaps, now im more confused than before
im afraid i dont understand Perl,
but im happy there is a way, now i just need to find out how to pass that to PHP,
i also dont understand the $width parameter you use there, why only width?
is that the width of the final background large container?
thank you very much again for the help Anthony, its so hard to find information about this, i really appreciate it
i wonder if the code is something like this
for ($i=1; $i<$number_texts;$i++) {
convert -size ${width}x -gravity $gravity -fill $color -background wheat \
-pointsize $pointsize -page +${x}+${y} label:"${text}" miff:-
}
convert -size 200x100 xc: - -flatten text_layered.png
but i just dont understand where to use the pipe to connect the loop with the final one
open( CMD, '| while read .... done | convert ... image_result.png' );
for ($i=1; $i<$number_texts;$i++) {
...
print CMD "$width $gravity .... $text\n";
...
}
close(CMD)