I wish to do something pretty simple;
I have an RGB image (let's call it a character, say "snoopy");
I wish to make an animation of small snoopy moving (sliding, really) across a large RGB background image, so a programmed sequence
of blits to successive (x,y) coordinates on the background will suit. ffmpeg can then make my frames into a video.
I would like snoopy not to be rectangular, so I have a gray scale mask (snoopy_shape).
I think all I need to do is first add the "snoopy_shape" to "snoopy" to make
an alpha'd snoopy ("snoopy_with_a_shape"), and then composite
snoopy_with_a_shape onto background at an x,y offset.
But I have just spent an hour reading manuals and (principally)
Anthony Thyssen's "Examples of ImageMagick Usage", and while
I now know quite a lot about the history of ImageMagick's handling
of transparency, various workrounds, old command line options, new
command line options, I'm no nearer knowing
the 2 commands I indeed to perform a masked blit operation.
Can anyone help?
The morass of compose and alpha
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: The morass of compose and alpha
It could be something like this.
Suppose snoopy.png is an image with the character and snoopy_mask.png is the same size as snoopy, white where the character is and black elsewhere. It is probably anti-aliased (ie a thin graduation between black and white. background.png is a larger image of the required background.
Change "100" to "101" to move snoopy right, etc.
Suppose snoopy.png is an image with the character and snoopy_mask.png is the same size as snoopy, white where the character is and black elsewhere. It is probably anti-aliased (ie a thin graduation between black and white. background.png is a larger image of the required background.
Code: Select all
convert ^
background.png ^
( snoopy.png snoopy_mask.png -compose CopyOpacity -composite ) ^
-gravity South ^
-geometry +0+100 ^
-compose Over -composite
out.png
snibgo's IM pages: im.snibgo.com
Re: The morass of compose and alpha
That's a very good basis for a solution to my problem.
Thank you.
BugBear
Thank you.
BugBear
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: The morass of compose and alpha
If snoopy.png and snoopy_mask.png are constant then so is everything within the brackets, so you could do this once:
Then each frame is:
If you have a fairly small number of frames, an efficient command could be:
Code: Select all
convert ^
snoopy.png snoopy_mask.png -compose CopyOpacity -composite ^
snoopy_shaped.png
Code: Select all
convert ^
background.png ^
snoopy_shaped.png ^
-gravity South ^
-geometry +0+100 ^
-compose Over -composite
out.png
Code: Select all
convert ^
background.png ^
snoopy_shaped.png ^
-gravity South ^
-compose Over ^
( -clone 0-1 -geometry +0+100 -composite -write f100.png +delete ) ^
( -clone 0-1 -geometry +0+101 -composite -write f101.png +delete ) ^
( -clone 0-1 -geometry +0+102 -composite -write f102.png +delete ) ^
NULL:
snibgo's IM pages: im.snibgo.com