Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#!/bin/bash
# This file:
#   http://anggtwu.net/MAXIMA/mkanim1.sh.html
#   http://anggtwu.net/MAXIMA/mkanim1.sh
#          (find-angg "MAXIMA/mkanim1.sh")
# Author: Eduardo Ochs <eduardoochs@gmail.com>
# Version: 2024oct15
# Public domain.
#
#
# Introduction
# ============
# "mkanim1.sh" is a shell library to produce animated gifs.
# This file is a friend of:
#   (find-angg "MAXIMA/topdf1.mac")
#
# In short: topdf1.mac is a library to produce animations in Maxima,
# but it only produces frames, each one as a separate PDF; then we can
# use the function "makeflipbook" in this file to produce a multipage
# PDF that works as a flipbook, and the function "makeanim" to convert
# the multipage PDF to an animated gif.
#
# I usually call just "makeboth" to produce the flipbook in PDF first,
# and then the animated git. For example:
#
#   mkanim1.sh makeboth anim.gif flipbook.pdf 001.pdf 002.pdf
#
#
# The internals
# =============
# When we run mkanim1.sh like above it defines some variables and shell
# functions - see the code below - and then runs this:
#
#        eval "makeboth anim.gif flipbook.pdf 001.pdf 002.pdf"
#
# We can make mkanim1.sh run more verbosely, or make it do a dry run,
# by using parameter assignments. For example:
#
#   mkanim1.sh ECHO=echo makeboth anim.gif flipbook.pdf 001.pdf 002.pdf
#
# "ECHO=echo" echoes some commands instead of running them;
# "ECHO=echo_and_run" echoes these commands and then runs them.
# See the test block at the end of this file for the details.
# For an example that works on real PDFs and gifs, see:
#
#   (find-angg "MAXIMA/topdf1.mac" "quick-demo")
#
#
# Etc
# ===
# See:
#   (find-bashnode "Environment" "parameter assignments")
#   (find-bashnode "Shell Parameter Expansion" "${@:7}")
#   (find-bashnode "Shell Parameter Expansion" "${PARAMETER:+WORD}")
#   (find-git-intro "1. Preparation")
#   (find-git-intro "1. Preparation" "wget" "GIT/eevgitlib1.sh")
#   (find-git-intro "2. A first test")
#   (find-git-intro "2. A first test" "/tmp/eevgitlib1.sh")
#   (find-es "imagemagick" "pdf-to-animated-gif")
#   (find-es "ps" "qpdf")
#   (find-es "ps" "qpdf-merge")
#   (find-es "ps" "glue-pages")


# «.variables»	(to "variables")
# «.functions»	(to "functions")
# «.eval»	(to "eval")
# «.tests»	(to "tests")


# «variables»  (to ".variables")
ECHO=""
DELAY=50
DENSITY=200
VERBOSE=""
IGOPTIONS="height=5cm"
GEOMETRY="a5paper,landscape"

# «functions»  (to ".functions")
echo_and_run    () { echo $*; $*; }
cdr             () { echo ${@:2}; }
add_1zs         () { for i in $*; do echo $i 1-z; done; }
makeboth        () { $ECHO makeflipbook $(cdr $*); $ECHO makeanim $1 $2; }
makeflipbook    () { $ECHO qpdf --empty --pages $(add_1zs $(cdr $*)) -- $1; }
makeanim        () {
  $ECHO convert -alpha deactivate ${VERBOSE:+-verbose} \
                -delay $DELAY -loop 0 -density $DENSITY $2 $1
}
includegraphics0 () { echo "\\includegraphics[$IGOPTIONS]{$1}"; }
includegraphics1 () { echo "\\newline"; echo "\$$(includegraphics0 $1)\$"; }
includegraphics  () { for i in $*; do includegraphics1 $i; done; }
includegraphics_fulltex () {
  echo "\\documentclass[oneside]{article}"
  echo "\\usepackage{graphicx}"
  echo "\\usepackage[$GEOMETRY]{geometry}"
  echo "\\begin{document}"
  includegraphics $*
  echo "\\end{document}"
}

# «eval»  (to ".eval")
eval "$*"


# «tests»  (to ".tests")
: <<'%%%%%'
* (eepitch-bash)
* (eepitch-kill)
* (eepitch-bash)
. ./mkanim1.sh
cdr     a b c d
add_1zs   b c d
ECHO=echo             makeflipbook      flipbook.pdf 001.pdf 002.pdf
ECHO=echo             makeanim anim.gif flipbook.pdf
ECHO=echo VERBOSE=1   makeanim anim.gif flipbook.pdf
ECHO=echo DENSITY=100 makeanim anim.gif flipbook.pdf
ECHO=echo DENSITY=100 makeboth anim.gif flipbook.pdf 001.pdf 002.pdf

includegraphics0        001.pdf
includegraphics1        001.pdf
includegraphics         001.pdf 002.pdf
includegraphics_fulltex 001.pdf 002.pdf

%%%%%



# Local Variables:
# coding:  utf-8-unix
# End: