Create a text fading effect for an animated gif

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
ravel

Create a text fading effect for an animated gif

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a text fading effect for an animated gif

Post 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.
ravel

Re: Create a text fading effect for an animated gif

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

Re: Create a text fading effect for an animated gif

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply