Page 1 of 1

[SOLVED] create 2 images from 4

Posted: 2012-07-21T14:32:46-07:00
by Draoidh
I have two B&W input images, which need to be stitched together to serve as mask in a later command.
Secondly, I need to create two canvases (or gradients) of the same size as the two input files and stitch them together.

This is how I did it (simplified example):

Code: Select all

convert pic1.svg pic2.svg \
\( -clone 0 -tile xc:yellow -draw "color 0,0 reset" \) \
\( -clone 1 -tile xc:red -draw "color 0,0 reset" \) \
-bordercolor black -border 5%   \
-append  -crop 100x50% out-%d.png
This achieves the desired result but I would be interested to know whether there's a more elegant way. It seems a bit daft to stitch all four together first and then split them into two.

Re: create 2 images from 4

Posted: 2012-07-24T23:45:04-07:00
by anthony
can you post an example of the images? and desired results?

Re: create 2 images from 4

Posted: 2012-07-25T07:47:29-07:00
by Draoidh
I have multiple graphics, each containing a line of text (black on transparent BG)

Image
and
Image

In a parameterized shell script, I stitch a pair of graphics together (one on top of the other). The parameters indicate, which pair, FG color of row 1, FG color of row 2 and BG color.

I have moved on a bit since I posted my question. As the final image might only have one row of "text" and as the specified colours might be gradients requiring me to determine the height of the individual rows of "text", I do this in three steps:

In the code I am pasting in below, to make it more readable and instantly replayable, I hard-code geometry and colours where my script uses variables:

1) create B&W mask of stitched graphics

Code: Select all

convert \
pic2.png -gravity south -extent x200% pic1.png \
-negate -bordercolor black \
-reverse -append -border 5% \
mask.png
Image

2) create foregound colour image
my code produces the result but is almost too embarrassing to post:

Code: Select all

convert \
pic2.png \
\( +clone -size 200x30 -tile gradient:yellow-green -draw "color 0,0 reset" \) \
-gravity south -extent x200% \
pic1.png \
\( +clone -size 200x43 -tile gradient:green-yellow -draw "color 0,0 reset" \) \
-delete 0,2 -reverse -append \
-bordercolor none -border 5% \
fg.png
The resultant image has the same dimensions as the mask and it contains two colour blocks where the two rows of text will be.
Image
3) create composite from mask, foreground image + background image

Code: Select all

convert mask.png -colorspace sRGB fg.png \
\( +clone -size 220x123  -tile xc:darkblue -draw "color 0,0 reset" \) \
-reverse -compose Src -composite \
final.png
Image

Result achieved but I am interested to learn if there's a more elegant approach. I am using IM 6.7.7.

Re: [SOLVED] create 2 images from 4

Posted: 2012-08-07T18:59:33-07:00
by anthony
Sorry very busy...

No that seems to be about the best.

You can do it in one line though, but in scripts it does not really matter than much.

Re: [SOLVED] create 2 images from 4

Posted: 2012-08-08T12:20:45-07:00
by Draoidh
Busy working on a fantastic product!