Page 1 of 1

The morass of compose and alpha

Posted: 2013-12-12T07:50:04-07:00
by bugbear
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?

Re: The morass of compose and alpha

Posted: 2013-12-12T11:19:19-07:00
by snibgo
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.

Code: Select all

convert ^
  background.png ^
  ( snoopy.png snoopy_mask.png -compose CopyOpacity -composite ) ^
  -gravity South ^
  -geometry +0+100 ^
  -compose Over -composite
  out.png
Change "100" to "101" to move snoopy right, etc.

Re: The morass of compose and alpha

Posted: 2013-12-13T03:12:07-07:00
by bugbear
That's a very good basis for a solution to my problem.

Thank you.

BugBear

Re: The morass of compose and alpha

Posted: 2013-12-15T06:32:08-07:00
by snibgo
If snoopy.png and snoopy_mask.png are constant then so is everything within the brackets, so you could do this once:

Code: Select all

convert ^
  snoopy.png snoopy_mask.png -compose CopyOpacity -composite ^
  snoopy_shaped.png
Then each frame is:

Code: Select all

convert ^
  background.png ^
  snoopy_shaped.png ^
  -gravity South ^
  -geometry +0+100 ^
  -compose Over -composite
  out.png
If you have a fairly small number of frames, an efficient command could be:

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: