#!/bin/sh VERSION="1.0.1" ARTIST="" # ================================================================================== # Configuration générale # ================================================================================== ORIENTATIONTAGVALUE="Orientation" DIR="." SIGNATUREPATH="/home/xxx/signaturegimp.png" QUALITY="100" # Programmes nécessaires EXIF=exif JHEAD=jhead MOGRIFY=mogrify # command line options signature="no" border="no" create_thumbnails="no" rotation="yes" extractthumbnails="no" # ================================================================================== # Taille par défaut pour le redimensionnement # ================================================================================== LSIZE1="800x800" LSIZE2="1024x1024" LSIZE3="1280x1280" LSIZE="" # ================================================================================== # Tailles prédéfinies pour le cadre noir (choisi selon la taille de la photo) # ================================================================================== B1SIZE0="150x150" # pour une photo 8 millions de pixels (3456x2304), équivaut à 4.5% de 3456 pixels B1SIZE1="36x36" B1SIZE2="46x46" B1SIZE3="58x58" B1SIZE=$B1SIZE0 B2SIZE0="5x5" # pour une photo 8 millions de pixels (3456x2304), équivaut à 0.15% de 3456 pixels B2SIZE1="1x1" B2SIZE2="2x2" B2SIZE3="2x2" B2SIZE=$B2SIZE0 SSIZE0="230" # pour une photo 8 millions de pixels (3456x2304), équivaut à 6.7% de 3456 pixels SSIZE1="62" SSIZE2="75" SSIZE3="95" SSIZE=$SSIZE0 # ================================================================================== # Fonctions # ================================================================================== usage() { printf "\nRetourne et réalise les traitements sur les photos du répertoire indiqué.\n\n" printf "Usage: $0 [option(s)]\n\n" printf "Informations :\n" printf "%4s-h or --help\t\tListe les options (ce message).\n" printf "%4s-v or --version\t\tAffiche la version courante de $0.\n\n" printf "Paramètres :\n" printf "%4s-p or --path\t\tRépertoire source des images (default \"$DIR\").\n" printf "%4s--no-rotation\t\tNe pas retourner la photo.\n" printf "%4s--rotation-only\t\tRetourner la photo uniquement (en fonction des informations EXIF), autres traitements désactivés.\n" printf "%4s-q or --quality\t\tQualité de l'image (default \"$QUALITY\").\n" printf "%4s-s or --size\t\tImage size : 0 (pas de retaillage - default), 1 ($LSIZE1), 2 ($LSIZE2) ou 3 ($LSIZE3).\n" printf "%4s--set-size\t\t\tSpécifier une taille précise pour la photo (exemple : \"$LSIZE1\").\n" printf "%4s-a or --artist\t\tRéinitialise le nom de l'artiste dans les informations EXIF (default \"$ARTIST\").\n\n" printf "%4s--set-artist\t\tRéinitialise le nom de l'artiste dans les informations EXIF (default \"$ARTIST\").\n" printf "Paramètres spécifiques (web notamment) :\n" printf "%4s--extract-thumbnails\tExtrait les thumbnails EXIF des fichiers traités (les fichiers produits seront nommés *.modified.jpeg).\n" printf "%4s--border\t\t\tAjouter un cadre noir à la photo.\n" printf "%4s--sign\t\t\tAjouter la signature.\n" printf "%4s--sign-path\t\t\tChemin du fichier signature à utiliser (default \"$SIGNATUREPATH\").\n" printf "%4s--orientation-tag\t\tNom du tag EXIF qui définit l'orientation de la photo (default \"$ORIENTATIONTAGVALUE\").\n" printf "%4s--for-web\t\t\t\"Pour le web\" - équivaut à --border --sign --size 1 --quality 85.\n" } get_exif_value () { LANG=C #$EXIF -t "$1" "$2" | grep Value | sed 's/^.*: //' $EXIF $1 | grep $ORIENTATIONTAGVALUE | cut -f2 -d '|' | tr -s ' ' } set_exif_value () { LANG=C $EXIF -t "$1" --ifd 0 --set-value "$2" --output "$3" "$3" >/dev/null 2>&1 } test_continue () { echo -n "Voulez-vous continuer (y/n) : " read CONTINUE case $CONTINUE in y | Y) ;; n | N) exit 0 ;; *) echo -n "Y/y ou N/n sont attendus. " test_continue ;; esac } # ================================================================================== # Définition des paramètres (parcours des arguments) # ================================================================================== while [ $# -gt 0 ] do case $1 in -h | --help) usage exit 0 ;; -v | --version) echo $VERSION exit 0 ;; -p | --path) DIR=$2 shift shift ;; -q | --quality) QUALITY=$2 shift shift ;; -s | --size) case $2 in 0) LSIZE="";; 1) LSIZE=$LSIZE1;; 2) LSIZE=$LSIZE2;; 3) LSIZE=$LSIZE3;; *) printf "Error, unknown size : \"$1\"\nRun '$0 --help' for details.\n"; exit 1;; esac shift shift ;; --set-size) LSIZE=$2 shift shift ;; --set-artist) setartist="yes" shift ;; -a | --artist) ARTIST="$2" setartist="yes" shift shift ;; --no-rotation) rotation="no" shift ;; --rotation-only) rotation="only" shift ;; --extract-thumbnails) extractthumbnails="yes" shift ;; --sign) signature="yes" shift ;; --sign-path) SIGNATUREPATH=$2 signature="yes" shift shift ;; --border) border="yes" shift ;; --orientation-tag) ORIENTATIONTAGVALUE=$2 shift shift ;; # GLOBAL CONFIG PARAMS --for-web) signature="yes" border="yes" LSIZE=$LSIZE1 QUALITY=85 shift ;; *) printf "Error, unknown option: \"$1\"\nRun '$0 --help' for details.\n" exit 1 ;; esac done # ================================================================================== # CONTROLES # ================================================================================== if [ $signature = "yes" ] && [ ! -f ${SIGNATUREPATH} ]; then echo "ERREUR : Fichier de signature \"${SIGNATUREPATH}\" introuvable !" exit 1 fi if [ $setartist = "yes" ] && [ `echo $ARTIST | wc -c` -lt 2 ]; then echo "ERREUR : Nom de l'artiste non défini !" exit 1 fi # définition des bordures selon la taille de l'image finale case $LSIZE in $LSIZE1) B1SIZE=$B1SIZE1; B2SIZE=$B2SIZE1; SSIZE=$SSIZE1;; $LSIZE2) B1SIZE=$B1SIZE2; B2SIZE=$B2SIZE2; SSIZE=$SSIZE2;; $LSIZE3) B1SIZE=$B1SIZE3; B2SIZE=$B2SIZE3; SSIZE=$SSIZE3;; *) B1SIZE=$B1SIZE0; B2SIZE=$B2SIZE0; SSIZE=$SSIZE0;; esac # ================================================================================== # Récapitulatif des paramètres # ================================================================================== echo "" echo "=========================================================" echo "Récapitulatif des paramètres" echo "=========================================================" echo "Rotation : $rotation" echo "Taille de l'image : $LSIZE" echo "Qualité de l'image : $QUALITY" echo "Bords noirs : $border" echo "Extraction des thumbnails : $extractthumbnails" echo "Artiste : $setartist ($ARTIST)" echo "Signature : $signature ($SIGNATUREPATH)" echo "=========================================================" test_continue $CONTINUE # ================================================================================== # MAIN # ================================================================================== for photo in `file $DIR/* | grep -i image | sed s/":"//g | awk '{print $1}'`; do #exifinfos=`file $photo | grep -i jpeg | sed s/":"//g | awk '{print $1}'` #if [ `echo $exifinfos | wc -c` -gt 1 ]; #then if [ $rotation = "yes" ] || [ $rotation = "only" ]; then orient=$(get_exif_value "$photo") printf "\tprocessing $photo...\n" case $orient in "top - left " | "haut - gauche") mogopt="-rotate 0" ;; "right - top " | "droit - haut") mogopt="-rotate 90" ;; "bottom - right " | "bas - droit") mogopt="-rotate 180" ;; "left - bottom " | "gauche - bas") mogopt="-rotate 270" ;; *) mogopt="" ;; esac # modification de l'orientation exif (top - left) set_exif_value Orientation 1 "$photo" fi ## TODO : ne pas redimensionner les photos si elles sont trop petites ## TODO : ne pas ajouter de bordures aux photos si elles sont trop petites # for i in `exif img_8931.jpg | grep -i dimension`; do echo $i | cut -f2 -d '|'; done if [ $rotation != "only" ]; then if [ $extractthumbnails = "yes" ]; then exif -e $photo fi if [ ! $LSIZE = "" ]; then mogopt="$mogopt -resize $LSIZE" fi # TODO : recalcul de la taille de la bordure en fonction de la taille de l'original if [ $border="yes" ]; then mogopt="$mogopt -bordercolor \"#CCCCCC\" -border $B2SIZE -bordercolor black -border $B1SIZE " fi # modification de la photo $JHEAD -q -dt -cmd "$MOGRIFY $mogopt -quality $QUALITY &i" "$photo" # modification de l'artiste if [ $setartist = "yes" ]; then set_exif_value Artist ${ARTIST} ${photo} fi # ajout signature à la photo # TODO : recalcul de la taille de la signature en fonction de la taille de l'original if [ $signature = "yes" ]; then composite -compose over -gravity southeast -dissolve 50% "${SIGNATUREPATH}" -resize $SSIZE "$photo" "$photo" fi fi #else # printf "\tWarning : ignoring photo $photo (probably not jpeg format) !\n" #fi done exit 0