-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animation Basics -- IM v6 Examples.html
1793 lines (1452 loc) · 111 KB
/
Animation Basics -- IM v6 Examples.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- saved from url=(0053)http://www.imagemagick.org/Usage/anim_basics/#dispose -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Animation Basics -- IM v6 Examples</title>
<link rel="icon" href="http://www.imagemagick.org/Usage/img_www/favicon.ico" type="image/x-icon">
<link rel="shortcut" href="http://www.imagemagick.org/Usage/img_www/favicon.ico" type="image/x-icon">
<link rel="canonical" href="http://www.imagemagick.org/Usage/anim_basics/">
</head><body bgcolor="#B0C4DE">
<h1>ImageMagick v6 Examples -- <br>
<img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="50" height="1">
Animation Basics</h1>
<div align="justify">
<dl>
<dt><b>Index</b>
</dt><dt><a href="http://www.imagemagick.org/Usage/"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_left.gif" border="0" width="15" height="15"> ImageMagick Examples Preface and Index</a>
</dt><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#gif_anim"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> GIF Animations and Animation Meta-data</a>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#dispose"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Frame Disposal Methods</a>
<ul>
<li><a href="http://www.imagemagick.org/Usage/anim_basics/#none">Dispose None</a> - overlay each frame in sequence
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Dispose Previous</a> - preserve background canvas
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Dispose Background</a> - clear to background
</li></ul>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#study"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Studying Animations</a>
<ul>
<li><a href="http://www.imagemagick.org/Usage/anim_basics/#identify">Identify</a> - information about an animation
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#adjoin">Adjoin</a> - splitting into individual frame images
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#coalesce">Coalesce</a> - fill out frames completely
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#montage">Frame Montage</a> - the "gif_anim_montage" script
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#list_info">List Information</a> - rebuild an existing animation
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#dispose_images">Disposal Images</a> - the GIF dispose form of the frames
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#deconstruct">Deconstruct</a> - report areas of frame differences
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#compare">Frame Comparisons</a> - more detailed frame differences
<dl><dd>
<a href="http://www.imagemagick.org/Usage/anim_basics/#compareany">Compare_Any</a>,
<a href="http://www.imagemagick.org/Usage/anim_basics/#compareclear">Compare_Clear</a>,
<a href="http://www.imagemagick.org/Usage/anim_basics/#compareoverlay">Compare_Overlay</a>
</dd></dl>
</li></ul>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#types"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Types of Animations</a>
<ul>
<li><a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Coalesced Animations</a>
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animations</a>
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animations</a>
</li><li><a href="http://www.imagemagick.org/Usage/anim_basics/#mixed">Mixed Disposal Animations</a>
</li></ul>
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#loop"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> The End of the Loop</a> - when an animation stops running
</dd><dd><a href="http://www.imagemagick.org/Usage/anim_basics/#zero"><img src="./Animation Basics -- IM v6 Examples_files/granitesm_right.gif" border="0" width="15" height="15"> Zero Delay Intermediate Frames</a>
</dd></dl>
These examples continue the previous example page on <a href="http://www.imagemagick.org/Usage/layers/">Layers of Multiple Images</a> but instead of layering multiple images on top
of each other to produce a single image, here we display each image for a
short period of time so as to produce an animation of images. <p></p>
The following section provides a basic understanding of the complexities of
animations and specifically GIF animations. It looks at the basic methods used
to generate animations, and how you can study existing animations to get an
understanding of how they work. <p></p>
This is recommended reading before going further in any of the later animation
sections. <p></p>
<hr><!-- ------------------------------------------------------------------ -->
<a name="gif_anim"></a>
<h2>GIF Animations and Animation Meta-data</h2>
The default way ImageMagick handles the output of an image list is to generate
a multi-page image. For the GIF image format, however, this takes the special
form of a 'GIF animation'.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert -delay 100 -size 100x100 xc:SkyBlue \
-page +5+10 balloon.gif -page +35+30 medical.gif \
-page +62+50 present.gif -page +10+55 shading.gif \
-loop 0 animation.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/animation.gif"><img src="./Animation Basics -- IM v6 Examples_files/animation.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
Here is a more advanced 'sparkle' example that uses a shell script
"<b><code><a href="http://www.imagemagick.org/Usage/scripts/star_field">star_field</a></code></b>". This
script was developed from my experiments in generating <a href="http://www.imagemagick.org/Usage/advanced/#stars">random star fields</a>. <p></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="" random="" script="" image="rose_sparkle.gif">
star_field 70x46 stars1.gif
star_field 70x46 stars2.gif
star_field 70x46 stars3.gif
convert rose: -compose Screen \
\( -clone 0 stars1.gif -composite \) \
\( -clone 0 stars2.gif -composite \) \
\( -clone 0 stars3.gif -composite \) \
-delete 0 -set delay 25 -layers Optimize rose_sparkle.gif
rm stars[123].gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/rose_sparkle.gif"><img src="./Animation Basics -- IM v6 Examples_files/rose_sparkle.gif" width="70" height="46" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
Basically three random star fields are generated, at the right size, then
overlaid onto our image, the IM built-in "<code>rose:</code>", using a
'<code><a href="http://www.imagemagick.org/Usage/compose/#screen">Screen</a></code>' alpha composition to
brighten the image with the given star patterns. The whole thing is then run
though the IM general GIF animation optimizer. <p></p>
The above may seem complex as it is using some advanced IM features I have yet
to introduce, but the result is a relatively simple, but well optimized three
frame animation. <p></p>
You can also look at some of the more complex animations that were created
using simple shell scripts for <a href="http://www.imagemagick.org/Usage/warping/#animations">Distortion
Animations</a>. <p></p>
There are a few extra IM settings which were created specifically for use in
GIF animations, and knowing about these is the first step into the world of GIF
animations... <p></p>
<table border="0" width="90%" align="center">
<tbody><tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose"><b>-dispose</b></a> {method}</code></td></tr><tr><td></td>
<td align="justify">
What the following images should do with the previous results of the GIF
animation. Valid options are '<code>Undefined</code>', '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>', '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>', and '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>. (See below for explanation of the settings)
<p></p>
</td></tr>
<tr valign="top"><td><nobr><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop"><b>-loop</b></a> {number}</code></nobr></td>
<td align="justify">
Number of times the GIF animation is to cycle though the image sequence
before stopping. It is an output 'image write' setting, so can be set
anywhere on the command line, though only the last such setting will be
used. <p></p>
Usually this set by default, to zero (infinite loop), however if any image
read in has a different value, then this setting will be set to that
images value. As such I recommend that you always set "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop">-loop</a></code>" when creating a GIF
animation, after all the images has been read in. <p></p>
For more information see <a href="http://www.imagemagick.org/Usage/anim_basics/#loop">The End of the Loop</a> below.
<p></p>
</td></tr>
<tr valign="top"><td><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay"><b>-delay</b></a> {time} </code></td>
<td align="justify">
Set the time delay (in 1/100th of a second) to pause after drawing the
images that are read in or created after this setting has been defined.
<p></p>
You can specify a different scale for the time delay by specifying a
'<code>x</code>' scaling (giving in ticks per second). For example
'<code>10x1</code>' is 10, 1 second ticks, while '<code>10x100</code>' is
10, one hundredth of a second ticks. <p></p>
Basically the '<code>x</code>' is equivalent to a fraction
'<code>/</code>' sign. For example if you specify '<code>1x160</code>'
will set a delay that is appropriate for 160 frames per second. <p></p>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
GIF animation delays must be specified in hundredths of a second for
correct working, which is why that is the default time unit. The
'<code>x</code>' factor is used more for generating other more movie
like formats, such a MNG's, and AVI's.
</i></font></td></tr></tbody></table><p></p>
</td></tr>
<tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?set"><b>-set</b></a> dispose {method}
<br><a href="http://www.imagemagick.org/Usage/option_link.cgi?set"><b>-set</b></a> delay {time}</code></td></tr><tr><td></td>
<td align="justify">
While the previous option settings will set image attributes on newly
created, or image that are read in, <i>after</i> that option is given, the
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?set">-set</a></code>" option is an
operator, that will allow you set image attributes on all images that have
<i>already</i> in the current image sequence. This allows you to change
the setting over a whole animation, or just a single frame, after the
images have been loaded or modified. <p></p>
</td></tr>
<tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?page"><b>-page</b></a> {w}x{h}+{x}+{y}</code></td></tr><tr><td></td>
<td align="justify">
This lets you set the offset position of the image about to be read in. As
this is a setting option, it only applies the geometry you give to images
that follow the setting. It does not effect images already read into
memory. <p>
If not given, or turned off using "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?page">+page</a></code>" the offset for the image read will be preserved. If
the image does not have an offset it will be positioned at
'<code>+0+0</code>' or the top left corner of the working canvas or
'page'. </p>
It can also be used to define a larger working canvas, by specifying a
width '<code>x</code>' height. Only the width and height page setting of
the first image in the sequence will be used to set the overall GIF
animation canvas size, all other page size settings will be ignored when
the animation is finally written. When a GIF animation is read in the
canvas size is set on all the frames in the animation. <p></p>
MNG animations can save frame offsets, but does not save canvas sizes.
The size of the first image defines the canvas size of the whole
animation. <p></p>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
The GIF image format can not specify a negative offset for images on a
canvas. If you try to use a negative offset IM will reset it to zero
when that image (or animation frame) is written to a GIF file. <p></p>
Positive offsets larger than the image canvas are quite acceptable but
may result in the image not appearing in the canvas drawing area when
displayed. How a GIF animation display program handles this is
undefined. Caution is advised.
</i></font></td></tr></tbody></table><p></p>
</td></tr>
<tr valign="top"><td colspan="2"><code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage"><b>-repage</b></a> {w}x{h}+{x}+{y}</code></td></tr><tr><td></td>
<td align="justify">
This is exactly like "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?page">-page</a></code>" except that it is an image operator instead of a
setting. That means you can use this to change or reset the 'page
geometry' of an image or animation frame that has already being read into
memory. <p></p>
The simpler "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>"
form, just resets the 'page geometry' of all images to the actual image in
each frame in the current image sequence to a zero offset, and the images
actual size. This operation is vital when you are extracting the
individual frames from an animation, (See the <a href="http://www.imagemagick.org/Usage/anim_basics/#adjoin">Adjoin
Examples</a> below). <p></p>
However "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>" will
destroy a lot of positioning information stored in each image, as such you
should also probably extract this information into a separate file for
later re-use. See <a href="http://www.imagemagick.org/Usage/anim_basics/#list_info">Animation List Information</a>
below. <p></p>
</td></tr></tbody></table><p></p>
<h3>Important Point</h3>
DO NOT save the intermediate, animations which you are not finished
processing, directly to GIF. You can use the IM internal format MIFF, as a
temporary file format, if you want to work on an animation in series of
separate processing steps. <p></p>
I repeat...<div align="center"><b>
Do not use GIF as an intermediate file format, use MIFF instead
</b></div><p></p>
If you made the big mistake of saving to GIF you would have just made the
resulting animation worse, as IM would have now performed an automatic <a href="http://www.imagemagick.org/Usage/quantize/#colors">Color Quantization</a>, to reduce the number of
colors present. Not only that but it did so on each frame completely
independently to every other frame, making any further processing,
particularly any GIF optimizations just that much harder. <p></p>
Solving this is a complex, multi-level problem, which is looked at in the next
section <a href="http://www.imagemagick.org/Usage/anim_opt/">Animation Optimization</a>. <p></p>
<hr><!-- ---------------------------------------------------------------- -->
<a name="dispose"></a>
<h2>Frame Disposal Methods</h2>
The first thing people creating GIF animation have trouble with is the
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" setting. This
is not surprising as it is a complex setting. Worse still a lot of animation
programs, including many web browsers, don't always handle the GIF disposal
meta-data setting correctly. However using the right disposal can make a big
difference to how well your animation works and optimizes. <p></p>
The first thing to remember in ImageMagick is that almost all the special
animation options, are settings for image reading. That is they are applied
to images that are read in, after, the setting has been given. The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?loop">-loop</a></code>" setting is the only one
typically used after the animation has been completed, just before the the
animation is saved. <p></p>
The basic task of the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" defines how an image is to be removed, <i>after</i> it
has been displayed for its "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" time period. That is, you need to give an image's "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" settings <i>before</i>
reading the image for that frame. But the action is applied after that image
is displayed. This is a little counter intuitive but does make sense in the
way IM operates on images. <p></p>
If you remember this, you should have no problems. <p></p>
The 'plus' forms of these options, like most other settings in IM stops the
setting being applied to any images being read in. That means if you don't
specify a setting, the frame image will continue to use the setting that was
read in with the image (if any). <p></p>
This can be important later when you want to read in a GIF animation for
further processing. Or when merging one GIF animation into another (the most
difficult animation technique). <p></p>
<a name="none"></a>
<h3>Dispose None <font size="-1">- each frame overlaid in sequence</font></h3>
The default "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>"
setting for GIF animations is '<code><b>Undefined</b></code>' which most
animation programs treats the same as a '<code><b>None</b></code>' disposal
setting. Basically this tells the computer to just leave whatever is overlaid
by this specific frame. Or more precisely, 'do nothing'. <p></p>
However please note that the whole canvas is always cleared at the end of the
animation sequence, before it loops and repeats. <p></p>
Here for example is a standard 'None dispose' animation...
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert -delay 100 -dispose None \
-page 100x100+5+10 balloon.gif \
-page +35+30 medical.gif \
-page +62+50 present.gif \
-page +10+55 shading.gif \
-loop 0 anim_none.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/anim_none.gif"><img src="./Animation Basics -- IM v6 Examples_files/anim_none.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
This disposal technique is ideal for animations which involve no form of
transparency, such as animations drawn on a solid, or patterned background.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert -dispose none -delay 100 \
-size 100x100 xc:SkyBlue +antialias \
-fill DodgerBlue -draw 'circle 50,50 15,25' \
-page +5+10 balloon.gif \
-page +35+30 medical.gif \
-page +62+50 present.gif \
-page +10+55 shading.gif \
-loop 0 canvas_none.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/canvas_none.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_none.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
Note that this technique can only add visible colors to an animation. It can
never actually make any part of an animation transparent again. (See <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animations</a> below). <p></p>
To also handle transparency need to use one of the other sorts of disposal
methods. <p></p>
<a name="previous"></a>
<h3>Dispose Previous <font size="-1">- preserve background canvas</font></h3>
The '<code><b>Previous</b></code>' disposal method is relatively simple. When
the current image is finished, return the canvas to what it looked like before
the image was overlaid. If the previous frame image also used a
'<code>Previous</code>' disposal method, then the result will be that same as
what it was before that frame.. etc.. etc.. etc... <p></p>
For example in this animation each of the later frames will return to the very
first frame of the image, which has a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>
disposal setting, before overlaying the image associated with that frame. <p></p>
The result is a background canvas that has just each frame image overlaid
for just the duration of that image...
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert -dispose none -delay 0 \
-size 100x100 xc:SkyBlue +antialias \
-fill DodgerBlue -draw 'circle 50,50 15,25' \
-dispose previous -delay 100 \
-page +5+10 balloon.gif \
-page +35+30 medical.gif \
-page +62+50 present.gif \
-page +10+55 shading.gif \
-loop 0 canvas_prev.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/canvas_prev.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
Note the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" method
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' used for the first image. This is
important, otherwise the 'previous' frame will go all the way back to the
original empty canvas that was present before the first frame. <p></p>
Also note that I used a "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" of '<code>0</code>' in the above animation. This says not
to wait before overlaying the first frame onto this 'background canvas'.
Without it you will see a short delay, showing just the canvas image with
nothing on top of it. <p></p>
Of course I need to still set a longer "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?delay">-delay</a></code>" for the later images, or they will appear and disappear in
the wink of an eye, and incidentally use up a lot of the viewers CPU cycles.
<p></p>
The use of the '<code>Previous</code>' disposal method can be prone to a
slight flickering, or pause in some web browsers, especially on slower
machines. Though that is quite rarely seen these days, the flicker itself is
still present, and something I consider to be a bug. See <a href="http://www.imagemagick.org/Usage/anim_basics/#zero">Zero Delay Frames</a> below for more specifics. <p></p>
Few animations make use of a dispose previous style of animation, the reason
is that it is very difficult for computers to optimise. The problem is just
what frame should the computer pick to become the background image? Simple
for us humans to figure out the best image to use, but difficult for a
computer decide. The best background image to use in an animation may not
even be meant to be displayed, such as in the current example, and as such
may not exist in an un-optimized version of that animation. <p></p>
<a name="background"></a>
<h3>Dispose Background <font size="-1">- clear to background</font></h3>
While the first two "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" methods are relatively simple, the
'<code><b>Background</b></code>' is probably the hardest to understand. <p></p>
When the time delay is finished for a particular frame, the area that was
overlaid by that frame is cleared. Not the whole canvas, just the area that
was overlaid. Once that is done then the resulting canvas is what is passed
to the next frame of the animation, to be overlaid by that frames image. <p></p>
Here for example we just replace each frame with the next frame.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert -delay 100 -dispose Background \
-page 100x100+5+10 balloon.gif \
-page +35+30 medical.gif \
-page +62+50 present.gif \
-page +10+55 shading.gif \
-loop 0 anim_bgnd.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/anim_bgnd.gif"><img src="./Animation Basics -- IM v6 Examples_files/anim_bgnd.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
So you can see exactly what is going on, lets add an initial canvas image to
the animation, so you can see how a '<code>Background</code>' actually
'disposes' that frame from the animation display.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert -delay 100 -dispose none \
-size 100x100 xc:SkyBlue +antialias \
-fill DodgerBlue -draw 'circle 50,50 15,25' \
-dispose background \
-page +5+10 balloon.gif \
-page +35+30 medical.gif \
-page +62+50 present.gif \
-page +10+55 shading.gif \
-loop 0 canvas_bgnd.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/canvas_bgnd.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_bgnd.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
As you can see as each overlaid frame is disposed of, that frames area is
cleared to transparency, before the next image is overlaid. This is the
importance of this GIF disposal method as it is the only way GIF animations
can clear any pixel regardless of an animations frame history. <p></p>
The only other way to clear pixels is to use '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' to go back to a frame in which those
pixels were clear. But that relies on knowing the history of the animation
sequence which makes it much more difficult for computers to optimize. <p></p>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/expert.gif" width="23" height="26"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="17" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
There is some thinking that rather than clearing the overlaid area to the
transparent color, this disposal should clear it to the 'background' color
meta-data setting stored in the GIF animation. In fact the old
"<code>Netscape</code>" browser (version 2 and 3), did exactly that. But
then it also failed to implement the '<code>Previous</code>' dispose
method correctly. <p></p>
On the other hand the initial canvas should also be set from the formats
'background' color too, and that is also not done. However all modern web
browsers clear just the area that was last overlaid to transparency, as
such this is now accepted practice, and what IM now follows.
</i></font></td></tr></tbody></table><p></p>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/warning.gif" width="28" height="28"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="12" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
Before IM version 6.2.6-1, the IM "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" operations
did not handle animations that used '<code>Background</code>' disposal to
make pixels transparent, as per all the major web browsers. See <a href="http://www.imagemagick.org/Usage/bugs/animation_bgnd/">Animation Bugs</a> for examples and
details. <p></p>
These functions however did work fine when no pixel clearing was applied
or intended. This has now been fixed for "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" and the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a> <a href="http://www.imagemagick.org/Usage/anim_opt/#optframe">OptimizeFrame</a></code>' method was created
to replace the use of "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?deconstruct">-deconstruct</a></code>" as a GIF animation frame optimizing function.
</i></font></td></tr></tbody></table><p></p>
<hr><!-- ---------------------------------------------------------------- -->
<a name="study"></a>
<h2>Studying Animations</h2>
Before we can continue with the basics of GIF animation, their types,
optimizations, and handling techniques, we need some techniques for studying
existing animations. <p></p>
<a name="identify"></a>
<h3>Identify
<font size="-1">- information about and animation</font></h3>
Now an animation consists of a lot of information packed into each individual
frame. You can see some of this information using the default IM
"<code><a href="http://www.imagemagick.org/Usage/basics/#identify">identify</a></code>" command.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="" nowarn="" out="identify_prev.txt">
identify canvas_prev.gif
</code></pre></td></tr></tbody></table>
<table border="0" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td>
<a href="http://www.imagemagick.org/Usage/anim_basics/identify_prev.txt"><img src="./Animation Basics -- IM v6 Examples_files/identify_prev.txt.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Text]"></a>
</td></tr></tbody></table>
</div><p></p>
<table cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/warning.gif" width="28" height="28"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="12" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
If you did not see output like the above your IM is a little old, and you
really should upgrade your installed version of ImageMagick, to the latest
version. If you don't you will be missing out on a lot of the new
advances in IM's handling and control of GIF animations.
</i></font></td></tr></tbody></table><p></p>
As you can see the actual image saved for the second and later frames is only
32x32 pixels, but all the frames sits on a 100x100 pixel 'virtual canvas' with
a 'virtual offset' on that larger canvas. <p></p>
To see more of the various bits of meta-data that is present you need to use
some of the more specialzed <a href="http://imagemagick.org/script/escape.php">percent Escape Formats</a> to get IM to output it.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="" nowarn="" out="identify_prev_more.txt">
identify -format "%f canvas=%Wx%H size=%wx%h offset=%X%Y %D %Tcs\n" \
canvas_prev.gif
</code></pre></td></tr></tbody></table>
<table border="0" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td>
<a href="http://www.imagemagick.org/Usage/anim_basics/identify_prev_more.txt"><img src="./Animation Basics -- IM v6 Examples_files/identify_prev_more.txt.gif" align="middle" vspace="0" hspace="0" border="0" alt="[IM Text]"></a>
</td></tr></tbody></table>
</div><p></p>
Which clearly shows not only the canvas size, image size and offset, but also
the disposal and time delays used for each individual frame. Note how the
first frame has the different disposal and time delay that was needed for
proper use of the later '<a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a>' disposal method.
<p></p>
<a name="adjoin"></a>
<h3>Adjoin
<font size="-1">- splitting an animation into frames</font></h3>
Now as you saw above, ImageMagick will by default try to save multiple images
into one file if that file format allows it. However as discussed in <a href="http://www.imagemagick.org/Usage/files/#write_list">Writing a Multi-Image List</a> IM will let you
use the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" setting
to tell it to save each image to disk as a separate individual image. <p></p>
For example, here we read in one of the GIF animations and output the individual
frame images in the animation sequence.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert canvas_prev.gif -scene 1 +adjoin frame_%03d.gif
</code></pre></td></tr></tbody></table>
<a href="./Animation Basics -- IM v6 Examples_files/frame_001.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_001.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/frame_002.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_002.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/frame_003.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_003.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/frame_004.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_004.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/frame_005.gif"><img src="./Animation Basics -- IM v6 Examples_files/frame_005.gif" width="100" height="100" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
</div><p></p>
If you were to examine the actual images above you will find that although
most web browsers show a larger 100x100 area, on which each sub-frame appears.
In fact most of the actual images show are really only just 32x32 pixels, just
as show in the previous 'identify' commands above. <p></p>
That is most of the area is just a canvas on which nothing is drawn, known as
the images 'page geometry' or 'virtual canvas'. The first
image of the animation defines that larger 'canvas' and every other frame
defines an 'offset' position on this larger canvas. <p></p>
This extra information is preserved in the frames that was saved by the
"<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" setting. As
as such you can easilly re-build the GIF animation. Not only is the page
information preserved in each separate frame image, but also any delay,
looping and GIF dispose settings, is also preserved. <p></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr valign="top"><td width="100%" align="justify">
This means that to rebuild the animation you only need to read all the images
in.
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert frame_???.gif anim_rebuilt.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/anim_rebuilt.gif"><img src="./Animation Basics -- IM v6 Examples_files/anim_rebuilt.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
Sometimes however you don't want to preserve this page geometry information.
For example if you want to use the individual frames for other projects. You
can reset the page size and offset using the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>" option, to remove the
'virtual canvas' information, leaving just the actual image. <p></p>
<br>
Normally when extracting animation sub-images you also generally reset the
images delay and dispose settings too to ensure they don't interfer with the
editing and display. <p></p>
For example here I remove the unwanted virtual canvas and offset and reset
the timing delays and disposals.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert canvas_prev.gif +repage -set delay 0 -set dispose None \
+adjoin repage_%03d.gif
</code></pre></td></tr></tbody></table>
<a href="./Animation Basics -- IM v6 Examples_files/repage_000.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_000.gif" width="100" height="100" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/repage_001.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_001.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/repage_002.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_002.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/repage_003.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_003.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/repage_004.gif"><img src="./Animation Basics -- IM v6 Examples_files/repage_004.gif" align="middle" vspace="5" hspace="10" border="1" alt="[IM Output]"></a>
</div><p></p>
Of course if you junk that meta-data, you need some way of recording and
editing that data. See <a href="http://www.imagemagick.org/Usage/anim_basics/#list_info">Animation List Information</a>
(below) for a script that extracts both the sub-images and saves the animation
meta-data, in a form that can be used to re-build the animation. <p></p>
<a name="coalesce"></a>
<h3>Coalesce
<font size="-1">- fill out frames completely</font></h3>
Viewing an animation in the form of the sub-frames, however is usually not very
useful, in a typical animation. <p></p>
For one thing, a highly optimized animation can consist of lots of very small
parts, without any visual indication of how they fit together. It can also
have a lot of other 'noise' that was added for <a href="http://www.imagemagick.org/Usage/anim_opt/#compress_opt">Compression Optimization</a> to reduce the
overall file size of the animation. <p></p>
For example, it is very difficult to figure out what this animation actually
did, just by looking at the individual sub-frames of the animation.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert script_k.gif +repage +adjoin script_k_%02d.gif
</code></pre></td></tr></tbody></table>
<nobr>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_00.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_00.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_01.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_01.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_02.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_02.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_03.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_03.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_04.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_04.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_05.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_05.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_06.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_06.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_07.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_07.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_08.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_08.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_09.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_09.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_10.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_10.gif" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
</nobr>
</div><p></p>
The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>"
operation basically converts an image into exactly what the animation should
look like after the previous frame has been correctly <a href="http://www.imagemagick.org/Usage/anim_basics/#dispose">disposed</a>, and the next sub-frame overlaid. <p></p>
That is instead of an animation sequence where each frame only represents the
overlaid changes to the previous 'disposed' frame. This operator creates a
complete view of the animation at each point, a bit like a true film strip,
rather than an animation sequence. Such a sequence, known as a <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Coalesced Animation</a> is much easier to study, edit,
modify and re-optimize. <p></p>
Here for example will generate a montage of the same 'confusing' animation
sequence I showed above, but this time we'll "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" the sequences, so
you can see what is really happening.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
montage script_k.gif -coalesce \
-tile x1 -frame 4 -geometry '+2+2' \
-background none -bordercolor none coalesce_k_montage.gif
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/script_k.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k.gif" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><div align="center">
<a href="./Animation Basics -- IM v6 Examples_files/coalesce_k_montage.gif"><img src="./Animation Basics -- IM v6 Examples_files/coalesce_k_montage.gif" align="middle" vspace="5" hspace="10" border="0" alt="[IM Output]"></a>
</div><p></p>
As you can see the result is like a film strip of the animation, allowing you
to clearly see how the previous pieces fit together to form a hand drawn
letter 'K'. <p></p>
As of IM version 6.2.6, the "<code>montage</code>" command understood the
use of "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>",
allowing you to create 'film strip' like image of the animation frames,
exactly as shown above. This version also contained fixes for coalesce, and
any GIF animation work should be at least this version (or better still the
latest version). <p></p>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/reminder.gif" width="20" height="16"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
An even better montage technique for examining animations is given in the
next example section.
</i></font></td></tr></tbody></table><p></p>
The "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" setting of
a <i>coalesced image sequence</i> is actually irrelevant, in a <a href="http://www.imagemagick.org/Usage/anim_basics/#coalesced">Coalesced Animation</a>. However for users piece of mind
the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" operator
will set the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>"
setting of each frame to either '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' or
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' as appropriate, so that
the coalesced image sequence will continue to animate correctly (as shown
above). <p></p>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tbody><tr valign="top">
<td><img src="./Animation Basics -- IM v6 Examples_files/expert.gif" width="23" height="26"><img src="./Animation Basics -- IM v6 Examples_files/space.gif" width="17" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>
A frame with a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>'
disposal means the next frame needed to clear at least one or more pixels,
to be displayed correctly. <p></p>
As such animations in which "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" added a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' dispose, means that the animation can not be
saved as a simple <a href="http://www.imagemagick.org/Usage/anim_basics/#overlay">Overlay Animation</a> (see below).
<p></p>
Technically, you can set all dispose settings of a coalesced image
sequence to either '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#background">Background</a></code>' or
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' to generate a <a href="http://www.imagemagick.org/Usage/anim_basics/#cleared">Cleared Frame Animation</a> (see below). Though not all
animations will optimize well in that form.
</i></font></td></tr></tbody></table><p></p>
Their are also some non-animation uses of the "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" operator. See <a href="http://www.imagemagick.org/Usage/layers/#coalesce">Coalesce, and Progressive Flattening</a>
examples of these uses. <p></p>
<br>
<a name="montage"></a>
<h3>Animation Frame Montage
<font size="-1">- the "gif_anim_montage" script</font></h3>
While "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" operator
will let you extract the actual images from an animation and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>" will let you see the
resulting frames of the animation, both methods leave out a lot of information
about the animation. <p></p>
By using some very careful manipulation of the animation images, you can
display the frames so as to show not only the actual frames, but also the
placement of those frames on the larger canvas. Here is one such method of
displaying an animation.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert -dispose Background script_k.gif -matte \
-compose Copy -bordercolor black -border 1x1 -compose Over \
-coalesce -bordercolor none -frame 4x4+2+2 \
-bordercolor none -border 2x2 +append script_k_parts.gif
</code></pre></td></tr></tbody></table>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_parts.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_parts.gif" align="middle" vspace="2" hspace="5" border="0" alt="[IM Output]"></a>
</div><p></p>
Here you can clearly see how the animation works. Each sub-frame image is
positioned so as to add to all the previous overlays. The result is a slowly
growing picture. Each frame is also a lot smaller than the 'virtual canvas'
on which it is positioned. <p></p>
I use this display technique a lot during the development and debugging of GIF
animations, as such I converted it into a shell script "<b><code><a href="http://www.imagemagick.org/Usage/scripts/gif_anim_montage">gif_anim_montage</a></code></b>", and
expanded it to also list some of the details above each frame in the
animation.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
gif_anim_montage script_k.gif script_k_frames.gif
</code></pre></td></tr></tbody></table>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/script_k_frames.gif" align="middle" vspace="2" hspace="5" border="0" alt="[IM Output]"></a>
</div><p></p>
Note the variations in the timings used in various frames, to pause as if the
pen is being lifted from the page and repositioned. Animations with variable
timing can be some of the most interesting, but also more difficult to handle,
as you will see in later IM Example pages. <p></p>
The "<code><a href="http://www.imagemagick.org/Usage/scripts/gif_anim_montage">gif_anim_montage</a></code>"
script also the special option '<code>-u</code>' which will also underlay a
semi-transparent copy of the coalesced animation. This lets you see how the
new sub-frames modifies the displayed animation.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
gif_anim_montage -u script_k.gif script_k_frames.png
</code></pre></td></tr></tbody></table>
<a href="./Animation Basics -- IM v6 Examples_files/script_k_frames.png"><img src="./Animation Basics -- IM v6 Examples_files/script_k_frames.png" align="middle" vspace="2" hspace="5" border="0" alt="[IM Output]"></a>
</div><p></p>
Of course this has semi-transparent pixels so a 'PNG' image format was needed,
OR you could use one of the many 'background' options that script also
provides, allowing you to use GIF or even JPEG formats for the resulting
summery image of the animation. <p></p>
Other options, lets you define the number of rows or columns to use, as well
as set various non-transparent backgrounds, or use a red box rather than
the default black. <p></p>
This script will be used a lot during the next few pages of IM Examples.
Suggestions and comments are welcome. <p></p>
<br>
<a name="list_info"></a>
<a name="sequence"></a> <!-- depreciate -->
<h3>Animation List Information
<font size="-1">- options used to build an animation</font></h3>
As I noted, using "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?adjoin">+adjoin</a></code>" and "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?coalesce">-coalesce</a></code>", as well as "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?repage">+repage</a></code>", are all useful methods of extracting and looking at GIF
animations. However they all destroy information about the original animation
in the process. <p></p>
You can see this extra information on framing, time delays, frame dispose,
etc., using the IM "<code>identify</code>" command with a "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?verbose">-verbose</a></code>" option. However I, and
probably most other users, find the output from this command, overwhelming
and not really directly usable. <p></p>
This is where another special shell script I wrote comes in. The "<b><code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code></b>" script will separate the
individual frames of the animation, but will also figure out exactly what IM
"<code>convert</code>" options you would need in order to re-build the
animation from those images. <p></p>
You can think of "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>" as
an animation disassembler, producing a summary of the animation in terms of IM
options. <p></p>
For example, lets decode the animation example we have been using to recover
the original "<code>convert</code>" settings used to create it, as well as
individual images used...
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
gif2anim canvas_prev.gif
</code></pre></td></tr></tbody></table>
<table border="0" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr><td>
<a href="http://www.imagemagick.org/Usage/anim_basics/canvas_prev.anim"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev.anim.gif" align="middle" vspace="5" hspace="0" border="0" alt="[IM Text]"></a>
</td></tr></tbody></table></td><td align="center">
<a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_001.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_001.gif" width="100" height="100" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_002.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_002.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_003.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_003.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_004.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_004.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_005.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_005.gif" width="32" height="32" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
<br></td></tr></tbody></table><p></p>
By default the "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>"
script uses the same base file name for the individual images and
"<code>.anim</code>" options file. As such the animation sequence file
generated by the above command is named "<code><a href="http://www.imagemagick.org/Usage/anim_basics/canvas_prev.anim">canvas_prev.anim</a></code>", with the individual frame images
"<code><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_001.gif">canvas_prev_001.gif</a></code>" to
"<code><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_005.gif">canvas_prev_005.gif</a></code>". <p></p>
If you examine the results more closely you will see that it actually did
manage to re-create the original options I used when I first created this GIF
animation (See <a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Dispose Previous Animation</a>). Also
while it is not important to actually generating an animation, the size, and
timings of the overlaid frames is also listed as a comment, to make it easier
to study. <p></p>
Rather than save the results to a file you can just list the animation
sequence options to the screen using a "<code>-l</code>" flag. That is just
output the animation sequence file, rather than save it, or the individual
frame images of the animation.
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code do_not_execute="">
gif2anim -l canvas_prev.gif
</code></pre></td></tr></tbody></table>
</div><p></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody><tr><td width="100%" align="justify">
Given a "<code>.anim</code>" file and the individual framing images,
a complementary script "<b><code><a href="http://www.imagemagick.org/Usage/scripts/anim2gif">anim2gif</a></code></b>" can be used to re-build the animation.
<table border="1" cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC">
<tbody><tr valign="top"><td><pre><code execute="">
anim2gif canvas_prev.anim
</code></pre></td></tr></tbody></table></td><td>
<a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_anim.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_prev_anim.gif" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td></tr></tbody></table><p></p>
The "<code><a href="http://www.imagemagick.org/Usage/scripts/anim2gif">anim2gif</a></code>" by default
will re-create the GIF animation with a "<code>_anim.gif</code>" suffix. You
can see that the resulting "<code><a href="./Animation Basics -- IM v6 Examples_files/canvas_prev_anim.gif">canvas_prev_anim.gif</a></code>" animation generated, looks and works exactly
like the original animation. <p></p>
This script simply replaces the special string "<code>BASENAME</code>" used in
the "animation sequence file", strips all comments, then just pass the convert
options that is left into the "<code>convert</code>" command. In other words
it treats the above file as a type of 'convert' script with comments. <p></p>
The reason a special string was used, is because this then allows you to
specify a different base filename than the name of the "<code>.anim</code>"
file itself. That way you can use a completely different set of frame images,
such as modified versions of the original, to recreate a different animation
from the old one. This is very useful feature, which will used in more
complex animation processing. (See <a href="http://www.imagemagick.org/Usage/anim_mods/#append">Appending
Animations Side-By-Side</a> for an example). <p></p>
Like "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>", the "<code><a href="http://www.imagemagick.org/Usage/scripts/anim2gif">anim2gif</a></code>" script has quite a number of
useful options, to help you process and modify animations. Some of these
options will be used later. For example see <a href="http://www.imagemagick.org/Usage/anim_mods/#append">Appending Animations</a>. <p></p>
Also as the "<code>.anim</code>" file is plain text you can use it take the
decoded images of an animation to adjust the GIF's meta-data, such as the
timings, positions, repeating sections of an animation, or adding new frames
and images to an animation. This was after all why I originally wrote the
scripts, long before I got involved with IM examples. <p></p>
For now the "<code><a href="http://www.imagemagick.org/Usage/scripts/gif2anim">gif2anim</a></code>" will be
most useful for examining an animation sequence to see just what is happening,
and the timings that is being applied between frames. <p></p>
<a name="dispose_images"></a>
<h3>Dispose Images
<font size="-1">- the GIF dispose form of the frames</font></h3>
This special "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?layers">-layers</a></code>"
method, '<code><b>Dispose</b></code>' shows what the frame should look like
<i>after</i> the time delay is finished, and the GIF dispose method has been
applied, but <i>before</i> the next frames image is overlaid. <p></p>
In other words this show exactly what the GIF "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" method setting actually
does to the frame, allowing you figure out exactly what is going wrong with
your animation. <p></p>
For example here is how each of our three <a href="http://www.imagemagick.org/Usage/anim_basics/#dispose">Dispose Method
Example Animations</a> look like after the individual frame dispose method was
applied. Remember each of these animations consist of a 'canvas image' that
was set with a '<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' "<code><a href="http://www.imagemagick.org/Usage/option_link.cgi?dispose">-dispose</a></code>" setting, then followed
by four smaller images overlaid then disposed of by the various GIF dispose
methods. <p></p>
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#none">None</a></code>' dispose animation...
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert canvas_none.gif -layers Dispose canvas_none_dispose.gif
gif_anim_montage canvas_none_dispose.gif canvas_none_dispose_frames.gif
</code></pre></td></tr></tbody></table>
<a href="./Animation Basics -- IM v6 Examples_files/canvas_none_dispose_frames.gif"><img src="./Animation Basics -- IM v6 Examples_files/canvas_none_dispose_frames.gif" align="middle" vspace="2" hspace="0" border="0" alt="[IM Output]"></a>
</div><p></p>
'<code><a href="http://www.imagemagick.org/Usage/anim_basics/#previous">Previous</a></code>' dispose animation...
<div align="center">
<table border="1" cellspacing="0" cellpadding="5" width="80%" bgcolor="#CCCCCC">
<tbody><tr><td><pre><code execute="">
convert canvas_prev.gif -layers Dispose canvas_prev_dispose.gif
gif_anim_montage canvas_prev_dispose.gif canvas_prev_dispose_frames.gif
</code></pre></td></tr></tbody></table>