Uniting different commands in a single one

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Uniting different commands in a single one

Post 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.
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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 ");
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Uniting different commands in a single one

Post 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 ");

?>
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Uniting different commands in a single one

Post 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
Image
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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post by javismiles »

hey Anthony, thank you very much for all of that, thats fantastic,
im going to try it out :)
Last edited by javismiles on 2010-12-10T19:15:13-07:00, edited 1 time in total.
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Uniting different commands in a single one

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Uniting different commands in a single one

Post 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:-
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Uniting different commands in a single one

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: Uniting different commands in a single one

Post 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)
Post Reply