Remarques sur le script

  • Le script sauvegarde l'image originale dans le répertoire 'old' et crée la nouvelle image dans le répertoire 'resized' : veillez-donc à ce que ces 2 répertoires soient créés avant de lancer le script.
  • Suivant le nom de fichier de vos photos, il faudra changer la variable $FILENAME. Sur mon Panasonic DMC-TZ5, les noms des photos sont de la forme : FILENAME="p$PictureNumber.JPG"
  • Le script redimensionne les images afin qu'elles aient la même hauteur : 630px. Vous pouvez changer ces valeurs en modifiant les variables $HORIZ_WIDTH et $VERT_WIDTH
  • Le script ajoute une annotation de 2 lignes sur la photo, respectivement $CAPTION1 et $CAPTION2 (cf. les sources du script ci-dessous)
  • Vous pouvez utiliser des polices de caractères différentes pour les 2 lignes en modifiant les variables $FONT1 et $FONT2.

Exemple d'utilisation du script

  • Image originale

Image originale

  • Image créée par le script

Image créée

Sources du script

#!/bin/sh
#
# bash script to resize, frame, annotate and add IPTC tags to a picture
# 
# @author : Thus0 <thus0@free.fr>
# @date : 2009/05/17

PictureNumber="1010569"
ObjectName="Tirta Empul Temple"
City="Tampaksiring"
Country="Bali"
Date="2009/05"
Keywords="Voyage"
Author="Thus0"

###############################################################################

# Parameters
HORIZ_WIDTH=780		# new width for horizontal picture
VERT_WIDTH=439		# new width for vertical picture
FONT1="bonzai.ttf"	        # Font for CAPTION1
FONT2="bonzai.ttf"	        # Font for CAPTION2

# Intermediate variables
Credit="$Date (c) $Author"
Caption="$City - $ObjectName"
CAPTION1="${Caption//\'/\'}"          # escaped caption
CAPTION2="$Country - $Credit"
FILENAME="p$PictureNumber.JPG"    # picture filename
NEW_FILENAME="$PictureNumber - $Country - $Caption.jpg"

# IPTC tags
IPTC_ObjectName="$ObjectName"
IPTC_Keywords="$Keywords,$Country,$City"
IPTC_City="$City"
IPTC_Country_PrimaryLocationName="$Country"
IPTC_Credit="$Credit"
IPTC_Source="$Author"
IPTC_Caption_Abstract="$Country - $Caption - $Credit"	# Caption-Abstract
IPTC_ImageOrientation=""

# Test if picture exists
if [ ! -f $FILENAME ]; then
	echo "$FILENAME does not exist !"
	exit
fi

# Test if picture is horizontal or vertical
IMG_WIDTH="`identify -ping -format '%w' $FILENAME`"
IMG_HEIGHT="`identify -ping -format '%h' $FILENAME`"
if [ $IMG_WIDTH -lt $IMG_HEIGHT ] ;then
	ORIENTATION="vertical"
	IPTC_ImageOrientation="P"
	NEW_WIDTH=$VERT_WIDTH
else
	ORIENTATION="horizontal"
	IPTC_ImageOrientation="L"
	NEW_WIDTH=$HORIZ_WIDTH
fi

# Convert picture
convert $FILENAME \
	-resize $NEW_WIDTH \
	-size 1x25 -mattecolor Black \
	-frame 10x10+5+5 xc:Black -background Black -append \
	-gravity SouthEast -font $FONT1 -pointsize 20 -fill white \
	-annotate +5+12 "$CAPTION1" \
	-gravity SouthEast -font $FONT2 -pointsize 18 -fill white \
	-annotate +5+0 "$CAPTION2" \
	"$NEW_FILENAME"

# Move original picture to folder 'old'
mv $FILENAME old/

# Add IPTC tags
echo "adding IPTC tags..."
exiftool -overwrite_original \
	-iptc:ObjectName="$IPTC_ObjectName" \
	-iptc:Keywords="$IPTC_Keywords" \
	-iptc:City="$IPTC_City" \
	-iptc:Country-PrimaryLocationName="$IPTC_Country_PrimaryLocationName" \
	-iptc:Credit="$IPTC_Credit" \
	-iptc:Source="$IPTC_Source" \
	-iptc:ImageOrientation="$IPTC_ImageOrientation" \
	-iptc:Caption-Abstract="$Country - $Caption - $Credit" \
	"$NEW_FILENAME"

# Move new picture to folder 'resized'
mv "$NEW_FILENAME" resized/

# done !
echo "done : $FILENAME ($ORIENTATION : $IMG_WIDTH x $IMG_HEIGHT)"
echo "     => $NEW_FILENAME"

Vous pouvez voir des exemples de photos dans ma gallerie photo picasa : http://picasaweb.google.com/thus0.petrus/