Page 1 of 1

Create a text fading effect for an animated gif

Posted: 2009-02-26T11:20:47-07:00
by ravel
Hi,

you already helped my creating an animated gif in this thread viewtopic.php?f=1&t=12882
Now I have to bother you again :)

I want to create an animated gif with a simple text fading effect.

Here is my not working approach, maybe you can see what i want to achieve:

Code: Select all

convert ( c:/banner.jpg ) ^
 ( -clone 0 -annotate 0x0+15+20 "Frame 1" -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 ) ^
 ( -clone 0 -annotate 0x0+15+20 "Frame 1" -font Arial -fill black -strokewidth 2 -pointsize 20 -delay 200 ) ^
 ( -clone 0 -annotate 0x0+15+20 "Frame 1" -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 ) ^
 ( -clone 0 -delay 100 ) ^
 ( -clone 0 -annotate 0x0+15+20 "Frame 2" -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 ) ^
 ( -clone 0 -annotate 0x0+15+20 "Frame 2" -font Arial -fill black -strokewidth 2 -pointsize 20 -delay 200 ) ^
 ( -clone 0 -annotate 0x0+15+20 "Frame 2" -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 ) ^
 ( -clone 0 -delay 100 ) ^
 -delete 0 -loop 0 -layers optimize c:/banner_animation.gif 
For lesser code length I have simplified the fading from grey to black to grey. later i will use the transparency thing (last 2 bits of the hex color)

I am trying to perform the following steps:
- Show "Frame 1" in grey for 100ms
- Show "Frame 1" in black for 2000ms
- Show "Frame 1" in grey for 100ms
- Show banner without text for 1000ms
- Show "Frame 2" in grey for 100ms
- Show "Frame 2" in black for 2000ms
- Show "Frame 2" in grey for 100ms
- Show banner without text for 1000ms

and so on...

My code is not even getting near to that what I want :P
The delay does not have any effect and the font, fontsize and color is no applied to the first frame.

Any advise?

Re: Create a text fading effect for an animated gif

Posted: 2009-02-26T12:50:24-07:00
by fmw42
Try setting the delay first, right before each clone parenthesis. Also I don't think your input image needs to be in parenthesis although it should not matter.

Alternately, you may be able to keep the delay in the parenthesis, but at the very first before clone, but then you probably need to add -respect-parenthesis right after convert.

Re: Create a text fading effect for an animated gif

Posted: 2009-02-26T13:06:27-07:00
by ravel
Thanks buddy!

This is the solution:

Code: Select all

convert ( c:/banner.jpg ) -respect-parenthesis ^
( -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 -clone 0 -annotate 0x0+15+20 "Frame 1" ) ^
( -font Arial -fill black -strokewidth 2 -pointsize 20 -delay 200 -clone 0 -annotate 0x0+15+20 "Frame 1" ) ^
( -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 -clone 0 -annotate 0x0+15+20 "Frame 1" ) ^
( -delay 100 -clone 0 ) ^
( -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 -clone 0 -annotate 0x0+15+20 "Frame 2" ) ^
( -font Arial -fill black -strokewidth 2 -pointsize 20 -delay 200 -clone 0 -annotate 0x0+15+20 "Frame 2" ) ^
( -font Arial -fill grey -strokewidth 2 -pointsize 20 -delay 10 -clone 0 -annotate 0x0+15+20 "Frame 2" ) ^
( -delay 100 -clone 0 ) ^
-delete 0 -loop 0 -layers optimize c:/banner_animation.gif  
I am using this code on a web server to create animated gifs so its important for me to make the gif creation as fast as possible without slowing down the server.
do you think there are any optimizations possible for this method?

Re: Create a text fading effect for an animated gif

Posted: 2009-02-28T18:05:50-07:00
by anthony
-delay does NOT effect -clone which copies the time delay from the original image being cloned. It only effects new image either created or read in.

To change a delay of an image already in memory use -set delay instead. though that effects ALL images in the current image sequence so probably should be done within the parenthesis.

the -morph operator can be used to generage fading from one image to another, very easilly. Though again delays can require tweeking as the new intermedate images get there timing delays from teh first image.

See IM Examples, Animation Modifications, Morph.
http://www.imagemagick.org/Usage/anim_mods/#morph