TetaTricks/chap/image.tex

109 lines
2.9 KiB
TeX
Raw Normal View History

2020-09-29 10:41:53 +02:00
\chapter{Image}
\label{chap:image}
2020-11-10 02:40:30 +01:00
Le traitement des images est un art à part entière. Nous allons
voir quelques grands classiques de la catégorie pas du tout
interactif. Le genre de machin que l'on peut ranger au fond
d'un script shell pour le réutiliser la semaine prochaine.
2020-09-29 10:41:53 +02:00
% -------------------------------------------------------------------
\section{ImageMagick}\index{ImageMagick}
2020-11-01 19:32:45 +01:00
Attention, ça va devenir \textsl{hardu}%
2020-11-10 02:40:30 +01:00
\footnote{Nous attendons tous avec impatience l'ouvrage magistral
de maitre Brunus},
2020-11-01 19:32:45 +01:00
l'abondance d'options
2020-11-10 02:40:30 +01:00
des outils ImageMagick est vraiment énorme, et leurs
2020-11-01 19:32:45 +01:00
interactions parfois troublantes\dots
\subsection{Écrire du texte}
Voici un exemple concret
(tiré du script d'encodage du \textsc{cloître}\index{cloître})
qui montre l'essentiel pour bien débuter. C'est une fonction
2020-11-10 02:40:30 +01:00
écrite en bash\index{bash} qui rajoute un texte sur une image. :
2020-11-01 19:32:45 +01:00
\begin{verbatim}
function tagpic
{
infile="$1"
outfile="$2"
texte="$3"
txtfont=" -font Utopia "
fontsize=" -pointsize 96 -kerning 6 "
color=" -fill Gray20 -stroke White "
txtopts=" -antialias -alpha off $txtfont "
convert $infile \
${txtopts} \
${txtfont} ${fontsize} \
${color} \
-gravity South \
-annotate +0+85 "${texte}" \
$outfile
}
\end{verbatim}
2020-11-10 02:40:30 +01:00
Quelques explications semblent nécessaires, parce que certaines
options sont un peu ésotériques...
\begin{itemize}
\item{txtfont}
\item{fontsize}
\item{colors}
\item{txtopts}
\item{-gravity}
\item{-annotate}
\end{itemize}
\subsection{Faire des GIFs animées}\index{GIF}
Ces images clignotantes sont l'essence même du Web\index{Web}
moderne depuis 1992, et \texttt{convert} sait très bien les
générer.
\begin{verbatim}
convert -delay 20 -loop 0 a.png b.png c.png foo.gif
\end{verbatim}
Ce sujet pertinent est abordé plus en détails en
page \pageref{chap:gif89a}
\subsection{Extraire une partie de l'image}
Dans cette fonctionnalité aussi, il semble y avoir quelques
subtilités.
\begin{verbatim}
DIM="1024x768"
convert -crop ${DIM}+512+0 $img $dst
\end{verbatim}
2020-09-29 10:41:53 +02:00
2020-11-01 19:32:45 +01:00
% -------------------------------------------------------------------
2020-09-29 10:41:53 +02:00
2020-11-01 19:32:45 +01:00
\section{Gmic}\index{Gmic}
2020-09-29 10:41:53 +02:00
2020-11-10 02:40:30 +01:00
XXX\index{XXX}
2020-09-29 10:41:53 +02:00
2020-11-10 02:40:30 +01:00
Existe aussi en plugin pour Gimp\index{Gimp}.
2020-09-29 10:41:53 +02:00
% -------------------------------------------------------------------
2020-11-10 02:40:30 +01:00
\section{NetPBM}\index{netpbm}\label{netpbm}
With the Netpbm file formats, its trivial to output pixels using
nothing but text based IO%
\footnote{https://www.vidarholen.net/contents/blog/?p=904}.
2020-09-29 10:41:53 +02:00
2020-11-10 02:40:30 +01:00
\begin{verbatim}
#!/bin/bash
exec > my_image.ppm # All echo statements will write here
echo "P3 250 250 255" # magic, width, height, max component value
for ((y=0; y<250; y++)) {
for ((x=0; x<250; x++)) {
echo "$((x^y)) $((x^y)) $((x|y))" # r, g, b
}
}
\end{verbatim}