-1

The backgroud pic: background

The final effect: gif effect

How do I make the red heart move and cover the background text?

I have tried this:

Convert back.png ( -clone1 -gravity center -geometry +10+10 heart.png ) (-clone 1 *******)

This just moves the heart, but did not cover the text.

How do I make the red heart move and mask part of the background text?

With mask?

fmw42
  • 46,825
  • 10
  • 62
  • 80
lion c
  • 47
  • 1
  • 3
  • 2
    Can you show us more of your code? Also read this: [How to ask question](https://stackoverflow.com/help/how-to-ask) – Martin54 Sep 21 '18 at 14:14
  • Where did you get these images? The creator probably created them by adding the text and heart onto the background of the animal only frame-by-frame. Post the image of the heart. What version of Imagemagick? Your have to either cover the text in each frame as the heart moves or start without the text and add it as the heart moves. You also must use composite to combine the background and heart. – fmw42 Sep 21 '18 at 19:04

1 Answers1

0

Here is one way using Imagemagick. First I need to crop out the heart shape from one of your animation frames, since you did not provide that.

Heart Image:

enter image description here

Background Image:

enter image description here

First, I create a new folder on my desktop called test and put both images into it.

Here is the code in (Bash) Unix syntax.

I start backwards from the right side towards the left of the background. The i indices are then reversed using j=(55-i) for later combining in alphabetic order. The jj computation adds a leading zero to the indices less than 10 so that all frames are listed in the test folder in alphabetic order.

For each frame, it extracts the alpha channel of the background and draws a black rectangle on the right side and then puts that result back into the alpha channel of the background image using -compose copy_opacity -composite. This effectively puts transparency where the pink letters are. Then I composite the heart image as the corresponding left edge of where I had drawn the black rectangle.

After the loop finishes, I gather all the frames from the test directory with names starting with tmp_ and create a gif animation that I write to the desktop.

x=564
for ((i=0; i<56; i++)); do
j=$((55-i))
jj=`printf "%02d\n" $j`
convert background.png \
\( -clone 0 -alpha extract -fill black -draw "rectangle $x,0 639,123" \) \
-alpha off -compose copy_opacity -composite \
heartshape.png -geometry +${x}+28 -compose over -composite tmp_$jj.gif 
x=$((x-8))
done
convert -dispose background -delay 10 tmp_*.gif -loop 0 ../heart_animation.gif


enter image description here

Note that Windows Imagemagick and scripting syntax is different. If some kind Windows user wants to post the conversion, that would be great.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • It works very good !Thanks a lot @fmw42,it 's my first question in stackoverflow,and get the perfect answer very quickly. Thanks! – lion c Sep 22 '18 at 04:44