|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
#!/bin/bash
# This file:
# http://anggtwu.net/myqdraw/mkanim1.sh.html
# http://anggtwu.net/myqdraw/mkanim1.sh
# (find-myqdraw "mkanim1.sh")
# See: http://anggtwu.net/eev-qdraw.html
# http://anggtwu.net/eev-qdraw.html#animations
# http://anggtwu.net/2024-bash-test-blocks.html
# (find-2024bashtesthsubs "0:00")
# Author: Eduardo Ochs <eduardoochs@gmail.com>
# Version: 2024dec12
# Public domain.
#
#
# Introduction
# ============
# "mkanim1.sh" is a shell library to produce animated gifs.
# This file is a friend of:
# (find-myqdraw "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
#
#
# This file was inspired by:
# (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")
# «.variables» (to "variables")
# «.makeanim» (to "makeanim")
# «.makeanim-tests» (to "makeanim-tests")
# «.latex» (to "latex")
# «.latex-tests» (to "latex-tests")
# «.why-library» (to "why-library")
# «.eval» (to "eval")
# «.eval-tests» (to "eval-tests")
# _ _ _
# __ ____ _ _ __(_) __ _| |__ | | ___ ___
# \ \ / / _` | '__| |/ _` | '_ \| |/ _ \/ __|
# \ V / (_| | | | | (_| | |_) | | __/\__ \
# \_/ \__,_|_| |_|\__,_|_.__/|_|\___||___/
#
# «variables» (to ".variables")
ECHO=""
DELAY=50
DENSITY=200
VERBOSE=""
IGOPTIONS="height=5cm"
GEOMETRY="a5paper,landscape"
# _ _
# _ __ ___ __ _| | _____ __ _ _ __ (_)_ __ ___
# | '_ ` _ \ / _` | |/ / _ \/ _` | '_ \| | '_ ` _ \
# | | | | | | (_| | < __/ (_| | | | | | | | | | |
# |_| |_| |_|\__,_|_|\_\___|\__,_|_| |_|_|_| |_| |_|
#
# «makeanim» (to ".makeanim")
# These functions call `qdpf' to glue several one-page/one-frame pdfs
# into a multi-page/multi-frame pdf can be used as a flipbook, and
# they call `convert' - from ImageMagick - to convert that flipbook to
# an animated gif.
#
# Note that:
# "ECHO=and_run commandandargs" echoes commandandargs and runs it, and
# "ECHO=echo commandandargs" echoes commandandargs instead of running it.
#
# The test block uses "ECHO=echo" to test the functions in this
# section in "dry run" mode. Compare with:
# (find-node "(make)Instead of Execution" "-n" "--dry-run")
#
# See:
# (find-bashnode "Environment" "parameter assignments")
# (find-bashnode "Shell Parameter Expansion" "${@:7}")
# (find-bashnode "Shell Parameter Expansion" "${PARAMETER:+WORD}")
# (find-es "imagemagick" "pdf-to-animated-gif")
# (find-es "ps" "qpdf")
# (find-es "ps" "qpdf-merge")
# (find-es "ps" "glue-pages")
#
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
}
# «makeanim-tests» (to ".makeanim-tests")
: <<'%%%%%'
* (eepitch-bash)
* (eepitch-kill)
* (eepitch-bash)
. mkanim1.sh
cdr a b c d
add_1zs b c d
ECHO=echo makeflipbook flipbook.pdf 1.pdf 2.pdf 3.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 1.pdf 2.pdf 3.pdf
%%%%%
# _ _____ __ __
# | | __ |_ _|__\ \/ /
# | | / _` || |/ _ \\ /
# | |__| (_| || | __// \
# |_____\__,_||_|\___/_/\_\
#
# «latex» (to ".latex")
includegraphics0 () { echo "\\includegraphics[$IGOPTIONS]{$1}"; }
includegraphics1 () { echo "\\newpage \$$(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}"
}
# «latex-tests» (to ".latex-tests")
: <<'%%%%%'
* (eepitch-bash)
* (eepitch-kill)
* (eepitch-bash)
. mkanim1.sh
includegraphics0 001.pdf
includegraphics1 001.pdf
includegraphics 001.pdf 002.pdf
includegraphics_fulltex 001.pdf 002.pdf
%%%%%
# _
# _____ ____ _| |
# / _ \ \ / / _` | |
# | __/\ V / (_| | |
# \___| \_/ \__,_|_|
#
# «why-library» (to ".why-library")
# «eval» (to ".eval")
# `mkanim1.sh' is a _library_ that defines several variables and shell
# functions, but it ends with the
#
# eval "$*"
#
# below, and that `eval' runs the arguments to `mkanim1.sh' in an
# environment in which all those variable and shell functions are
# defined. For example, consider these three lines:
#
# [1] ./mkanim1.sh ECHO=echo makeboth anim.gif flipbook.pdf 001.pdf 002.pdf
# [2] eval "ECHO=echo makeboth anim.gif flipbook.pdf 001.pdf 002.pdf"
# [3] ECHO=echo makeboth anim.gif flipbook.pdf 001.pdf 002.pdf
#
# When we run [1] it defines several variables and functions,
# including `ECHO=' and `makeboth () {...}', and then it runs the
# `eval "$*"'; that `eval "$*"' runs [2], that runs [3] in that
# environment; the `ECHO=echo' overrides the `ECHO=' from here,
#
# (to "variables")
#
# and then the `makeboth' just echoes this:
#
# makeflipbook flipbook.pdf 001.pdf 002.pdf
# makeanim anim.gif flipbook.pdf
#
# it does a "dry run", in this sense:
#
# (find-node "(make)Instead of Execution" "-n" "--dry-run")
#
eval "$*"
# «eval-tests» (to ".eval-tests")
: <<'%%%%%'
* (eepitch-bash)
* (eepitch-kill)
* (eepitch-bash)
./mkanim1.sh
./mkanim1.sh ECHO=echo makeboth anim.gif flipbook.pdf 001.pdf 002.pdf
./mkanim1.sh ECHO=echo makeflipbook flipbook.pdf 001.pdf 002.pdf
./mkanim1.sh ECHO=echo makeanim anim.gif flipbook.pdf
%%%%%
# Local Variables:
# coding: utf-8-unix
# End: