-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanim2gif
123 lines (107 loc) · 3.94 KB
/
anim2gif
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
#!/bin/sh -
#
# anim2gif [-b BASENAME] file.anim...
#
# This is a simple script to magick my own animation sequence file
# which basically is a list of IM command line options, with added
# comments back into a GIF Animations. file.anim --> file_anim.gif
#
# The animation sequence file can be extracted from an existing GIF animation
# using the "gif2anim" script. It can also be generated using some other
# porgram, or by hand. It does not actually even need to generate a GIF
# animation but could actually be any sequence of "magick" command line
# options. However it is designed for generating GIF aniamtions.
#
# OPTIONS
# -b framename basename for the individual frames
# -g Add '.gif' to end of basename, not '_anim.gif'
# -c Input frames are coalesced, ignore any initial page size
#
# The options basically perform slight modifications to the input animation
# sequence file, and assumes it is in the format generated by the "gif2anim"
# script. They are provided for convenience only.
#
# It does not currently attempt to optimize the animation in any way, unless
# that optimization was given in the animation sequence file given.
#
####
#
# WARNING: Input arguments are NOT tested for correctness.
# This script represents a security risk if used ONLINE.
# I accept no responsiblity for misuse. Use at own risk.
#
# Anthony Thyssen 20 April 1996
#
ORIGDIR=`pwd`
PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path
PROGDIR=`dirname $PROGNAME` # extract directory of program
PROGNAME=`basename $PROGNAME` # base name of program
Usage() { # output the script comments as docs
echo >&2 "$PROGNAME:" "$@"
sed >&2 -n '/^###/q; /^#/!q; s/^#//; s/^ //; 3s/^/Usage: /; 2,$ p' \
"$PROGDIR/$PROGNAME"
exit 10;
}
#VERBOSE= # report the animation images being processed
#debug=true # debug the magick line executed
basename= # use this name for the individual frame images
sfx=_anim.gif # the suffix to and to created GIF animation
COALESCED= # frames are coalesced, ignore initial set page size option
while [ $# -gt 0 ]; do
case "$1" in
--help|--doc*) Usage ;;
-b) shift; basename="$1" ;;
-g) sfx=.gif ;;
-c) COALESCED='/^-page [0-9][0-9]*x[0-9][0-9]*$/d' ;;
--debug) debug=true ;;
--) shift; break ;; # end of user options
-*) Usage "Unknown option \"$1\"" ;;
*) break ;; # end of user options
esac
shift # next option
done
[ $# -gt 1 ] && VERBOSE=true # report each file as it is magicked
for i in "$@" ; do
if [ ! -r "$i" ]; then
echo >&2 "Unable to read \"$i\""
continue
fi
[ "$VERBOSE" ] && echo "magicking \"$i\""
path=`expr "$i" : '\(.*\)/'` # get file path (if any)
name=`expr "//$i" : '.*/\([^/]*\)'` # remove path to file
suffix=`expr "$name" : '.*\.\([^./]*\)$'` # extract last suffix
name=`expr "$name" : '\(.*\)\.[^.]*$'` # remove last suffix
: ${path:=.}
bname="$name"
[ "$basename" ] && bname="$basename"
case "$suffix" in
anim) ;;
*) echo >&2 "Skipping Non Animation file: \"$i\""
continue ;;
esac
# This is the heart of the animation creator
# The sed script removes comments from the scripts options
# though ensures it does not remove any #RRGGBB color arguments.
#
cd $path
[ "$debug" ] && set -x
#magick -adjoin -colors 256 \
sed 's/#[^0-9a-fA-F].*//; s/#$//;
s/[ >:::]*$//;
'"$COALESCED"';
s/BASENAME/'"$bname"'/;
/^$/d;
' $name.$suffix |\
magick `cat` $ORIGDIR/$bname$sfx 2>&1
#|| echo "anim2gif: Convert returned failed error status $?"
#|| rm -f $ORIGDIR/$bname$sfx
[ "$debug" ] && set -
# Return to the original directory
cd $ORIGDIR
# Removed as being obsolete.
#[ -f $bname$sfx ] &&
# gifsicle -O2 --batch $bname$sfx
if [ ! -f "$bname$sfx" ]; then
echo >&2 "anim2gif: Failed to magick \"$i\" into \"$bname$sfx\""
fi
done