Page 1 of 1

how to use just one IM call?

Posted: 2010-08-11T08:08:54-07:00
by papoola
Hi everyone,, I am really thankful to be able to use ImageMagick in my software to render files.
Currently I have created template files which contain reference to images + render settings. Depending on arguments mentioned in these template files software will call IM convert.exe several times. These call are more or less like these:

Code: Select all

// input images
convert.exe "xxxxx1.jpg" .....  "xxxxx1.miff"
convert.exe "xxxxx2.jpg" .....  "xxxxx2.miff"
convert.exe "xxxxx3.jpg" .....  "xxxxx3.miff"
// output image
convert.exe xc:white -resize ?x? -draw "image Over ?,? 0,0 'xxxxx1.miff'" -draw "image Over ?,? 0,0 'xxxxx2.miff'" -draw "image Over ?,? 0,0 'xxxxx3.miff'" -quality 100 "output.jpg"
As you can see with this approach I render input images as seperate .miff files and then combine them together at last call by using -draw image.
I am wondering if there is a way to this in one IM convert call and having following things in mind:
  • I still should be able to resize/rotate/... all input images( "xxxxx1.jpg"/ "xxxxx2.jpg"/ "xxxxx3.jpg"/...)
  • input items could be placed at desired position in "output.jpg"

Re: how to use just one IM call?

Posted: 2010-08-11T08:13:54-07:00
by ProfessorJerk
Well for starters you can combine all your conversions from to miffs using the frame number replacement syntax

convert.exe "xxxx%03d.jpg"[1-3] ..... "xxxx%03d.miff"

Re: how to use just one IM call?

Posted: 2010-08-11T09:21:44-07:00
by el_supremo
If you know you will have, for example, three input images then try structuring a command like this:

Code: Select all

convert.exe -size ?x? xc:white ( "xxxxx1.jpg" .....  ) -geometry +?+? -composite ( "xxxxx2.jpg" .....  ) -geometry +?+? -composite  ( "xxxxx3.jpg" .....  ) -geometry +?+? -composite -quality 100 "output.jpg"
I've changed "xc:white -resize ?x?" to "-size ?x? xc:white" which might perform better. Each of the input images is processed (rotated etc.) within a pair of parentheses.
If you have a varying number of input images perhaps you can script this so that you build up a command and then execute it.

Pete

Re: how to use just one IM call?

Posted: 2010-08-11T19:46:44-07:00
by anthony
el_supremo wrote:If you know you will have, for example, three input images then try structuring a command like this:

Code: Select all

convert.exe -size ?x? xc:white ( "xxxxx1.jpg" .....  ) -geometry +?+? -composite ( "xxxxx2.jpg" .....  ) -geometry +?+? -composite  ( "xxxxx3.jpg" .....  ) -geometry +?+? -composite -quality 100 "output.jpg"
I've changed "xc:white -resize ?x?" to "-size ?x? xc:white" which might perform better. Each of the input images is processed (rotated etc.) within a pair of parentheses.
If you have a varying number of input images perhaps you can script this so that you build up a command and then execute it.

Pete
I would use some form of line breaks to make the command simplier to follow

Code: Select all

convert.exe -size ?x? xc:white  \
        ( "xxxxx1.jpg" .....  ) -geometry +?+? -composite \
        ( "xxxxx2.jpg" .....  ) -geometry +?+? -composite  \
        ( "xxxxx3.jpg" .....  ) -geometry +?+? -composite \
        -quality 100 "output.jpg"
Also see IM Examples, Layered Images for other methods. Especially look at
Examples of Layering images
http://www.imagemagick.org/Usage/layers/#example

The second example uses a two stage approach. A loop to do the individual image processing, piping into a final image layering command.

Re: how to use just one IM call?

Posted: 2010-08-12T23:25:23-07:00
by papoola
Thank you guys.. :D I always assumed it might be possible to do that but didn't think that it would be that easy.
ProfessorJerk I still need to pass seperate parameters (like resize/rotate/...) for each image so I think approach suggested by el_supremo works way I want it. Anthony thank you for additional info. I will take a look at the two stage approach with pipline if parentheses approach wont work well for me.

8)