[SOLVED] create 2 images from 4

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?".
Post Reply
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

[SOLVED] create 2 images from 4

Post 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.
Last edited by Draoidh on 2012-07-29T03:43:54-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: create 2 images from 4

Post by anthony »

can you post an example of the images? and desired results?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: create 2 images from 4

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

Re: [SOLVED] create 2 images from 4

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: [SOLVED] create 2 images from 4

Post by Draoidh »

Busy working on a fantastic product!
Post Reply