GIFs animées, utiliser Bash

GNU Bourne-Again SHell : Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). Bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1).

J'crois que c'est clair, dans notre contexte, Bash semble être un outil tout indiqué.

Noms des fichiers

Il faut utiliser le printf du shell pour formater correctement les nombres afin qu'ils soient classés dans le bon ordre, en utilisant une spécification telle que "%03d". Exemple :

tth@plop:~/Essais/GIF$ foo=$(printf /tmp/picz%03d.png 42)
tth@plop:~/Essais/GIF$ echo $foo
/tmp/picz042.png
tth@plop:~/Essais/GIF$ 

Arguments du script

Pour passer (et comprendre) un argument à votre script, voici la petite recette de base :

if [ $# == 1 ] ; then
	JOB=$1
else
	JOB=plop
fi

Utiliser des fonctions

Une fonction permet de regrouper une séquence d'instructions afin d'en faire un bloc réutilisable à loisir. En voici un exemple qui sert à rajouter un petit texte bicolore sur une image :

function annotate()
{
echo ======== annotate \"$1\" sur $2

convert 				\
	-fill blue -pointsize 22	\
	-annotate +10+19 "$1"		\
	-fill yellow -pointsize 22 	\
	-annotate +12+21 "$1"		\
	$2 $2
}

Certes oui, cela semble prometteur, mais comment utiliser cette fonctions ? Facilement, en fait. D'abord il faut l'enregistrer dans un fichier que l'on peut nommer (par exemple) functions_gif.bash puis ensuite mettre à contribution comme ça :

tth@plop:~/Essais/GIF$ cp regard_1.jpg regard_2.jpg
tth@plop:~/Essais/GIF$ source functions_gif.bash 
chargement des fonctions.
tth@plop:~/Essais/GIF$ annotate "we make porn" regard_2.jpg
======== annotate "we make porn" sur regard_2.jpg
tth@plop:~/Essais/GIF$ 

Les boucles

Deux exemples àlc. Parcourir une liste de fichiers :
for i in *.png
do
	identify $i
done
Et créer des noms séquentiels :
for (( i=1; i<=10; i++ ))
do
        name=$(printf "img%05d.tga" $i
done

Faire des calculs

$ FOO=21
$ BAR=$(( FOO * 2 ))
$ echo $BAR
42

C'est tout pour le moment.