-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_gifs.sh
executable file
·149 lines (132 loc) · 5.82 KB
/
generate_gifs.sh
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
#!/bin/bash
[ -z "${CONVERT_COMMAND}" ] && CONVERT_COMMAND="convert"
[ -z "${MOGRIFY_COMMAND}" ] && MOGRIFY_COMMAND="mogrify"
GIF_OUTPUT_DIR="./gifs"
FRAME_OUTPUT_DIR="${GIF_OUTPUT_DIR}/frames"
mkdir -p "${GIF_OUTPUT_DIR}"
mkdir -p "${FRAME_OUTPUT_DIR}"
# Static gif with no animation, no transparency
${CONVERT_COMMAND} -dispose none \
-size 100x100 xc:DarkSeaGreen \
-fill PaleGreen -draw "circle 50,50 15,25" \
-loop 1 \
"${GIF_OUTPUT_DIR}/static_nontransparent.gif"
# Regular gif with 4 frames, no loop, no transparency
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:DarkSeaGreen \
-fill PaleGreen -draw "circle 50,50 15,25" \
-dispose none -delay 100 \
-page +10+10 -size 30x30 xc:LightSalmon \
-page +30+30 -size 40x40 xc:SkyBlue \
-page +60+60 -size 30x30 xc:Khaki \
-loop 1 \
"${GIF_OUTPUT_DIR}/animated_noloop.gif"
# Animated gif with 4 frames, looping forever, no transparency
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:DarkSeaGreen \
-fill PaleGreen -draw "circle 50,50 15,25" \
-dispose none -delay 100 \
-page +10+10 -size 30x30 xc:LightSalmon \
-page +30+30 -size 40x40 xc:SkyBlue \
-page +60+60 -size 30x30 xc:Khaki \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_loop.gif"
# As above, but interlaced
INTERLACED_GIF_PATH="${GIF_OUTPUT_DIR}/animated_loop_interlaced.gif"
cp "${GIF_OUTPUT_DIR}/animated_loop.gif" "${INTERLACED_GIF_PATH}"
${MOGRIFY_COMMAND} -interlace gif "${INTERLACED_GIF_PATH}"
if ! identify -verbose "${INTERLACED_GIF_PATH}" | grep "Interlace: GIF" >/dev/null ; then
echo "mogrify does not support creating interlaced GIFs"
echo "exiting..."
exit 1
fi
# Animated gif with 4 frames, looping forever, no transparency, variable delay
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:DarkSeaGreen \
-fill PaleGreen -draw "circle 50,50 15,25" \
-dispose none -delay 100 \
-page +10+10 -size 30x30 xc:LightSalmon \
-delay 10 \
-page +30+30 -size 40x40 xc:SkyBlue \
-delay 100 \
-page +60+60 -size 30x30 xc:Khaki \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_loop_variable_delay.gif"
# Static transparent gif with no animation
${CONVERT_COMMAND} -dispose none \
-size 100x100 xc:transparent \
-fill DarkSeaGreen -draw "circle 50,50 15,25" \
-loop 1 \
"${GIF_OUTPUT_DIR}/static_transparent.gif"
# Transparent gif with 4 frames, loops forever
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:transparent \
-fill DarkSeaGreen -draw "circle 50,50 15,25" \
-dispose background -delay 100 \
-page +10+10 -size 30x30 xc:LightSalmon \
-page +30+30 -size 40x40 xc:SkyBlue \
-page +60+60 -size 30x30 xc:Khaki \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_transparent_loop.gif"
# Transparent gif with 4 frames, loops forever, restore previous
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:transparent \
-fill DarkSeaGreen -draw "circle 50,50 15,25" \
-dispose previous -delay 100 \
-page +10+10 -size 30x30 xc:LightSalmon \
-page +30+30 -size 40x40 xc:SkyBlue \
-page +60+60 -size 30x30 xc:Khaki \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_transparent_restoreprev_loop.gif"
# Transparent gif with 4 frames, loops forever, first frame restore previous
${CONVERT_COMMAND} -dispose previous -delay 100 \
-size 100x100 xc:transparent \
-fill DarkSeaGreen -draw "circle 50,50 15,25" \
-page +10+10 -size 30x30 xc:LightSalmon \
-page +30+30 -size 40x40 xc:SkyBlue \
-page +60+60 -size 30x30 xc:Khaki \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_transparent_firstframerestoreprev_loop.gif"
# Transparent gif with 4 transparent frames, loops forever, no dispose
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:transparent \
-fill DarkSeaGreen -draw "circle 50,50 15,25" \
-page +10+10 \( -size 30x30 xc:transparent -fill LightSalmon -draw "circle 15,15 5,5" \) \
-page +20+20 \( -size 40x40 xc:transparent -fill SkyBlue -draw "circle 20,20 10,5" \) \
-page +30+30 \( -size 30x30 xc:transparent -fill Khaki -draw "circle 15,15 5,5" \) \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_transparent_frame_norestore_loop.gif"
# Transparent gif with 4 transparent frames, loops forever, restore background
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:transparent \
-fill DarkSeaGreen -draw "circle 50,50 15,25" \
-dispose background \
-page +10+10 \( -size 30x30 xc:transparent -fill LightSalmon -draw "circle 15,15 5,5" \) \
-page +20+20 \( -size 40x40 xc:transparent -fill SkyBlue -draw "circle 20,20 10,5" \) \
-page +30+30 \( -size 30x30 xc:transparent -fill Khaki -draw "circle 15,15 5,5" \) \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_transparent_frame_restorebackground_loop.gif"
# Transparent gif with 4 transparent frames, loops forever, restore previous
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:transparent \
-fill DarkSeaGreen -draw "circle 50,50 15,25" \
-dispose previous -delay 100 \
-page +10+10 \( -size 30x30 xc:transparent -fill LightSalmon -draw "circle 15,15 5,5" \) \
-page +30+30 \( -size 40x40 xc:transparent -fill SkyBlue -draw "circle 20,20 10,5" \) \
-page +60+60 \( -size 30x30 xc:transparent -fill Khaki -draw "circle 15,15 5,5" \) \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_transparent_frame_restoreprev_loop.gif"
# Transparent gif with 4 frames, several out of bounds, loops forever
${CONVERT_COMMAND} -dispose none -delay 100 \
-size 100x100 xc:transparent \
-page +200+0 -fill DarkSeaGreen -draw "circle 50,50 15,25" \
-dispose background -delay 100 \
-page +10+10 -size 30x30 xc:LightSalmon \
-page +30+30 -size 40x40 xc:SkyBlue \
-page +60+60 -size 50x50 xc:Khaki \
-loop 0 \
"${GIF_OUTPUT_DIR}/animated_transparent_loop_frames_out_of_bounds.gif"
# Output individual coalesced frames
for f in "${GIF_OUTPUT_DIR}"/*.gif; do
${CONVERT_COMMAND} +adjoin -coalesce "${f}" "${FRAME_OUTPUT_DIR}/$(basename "${f}" .gif).png"
done