#!/bin/bash
# thanks to Remi, Anvil & NaiosKAE The Korrigan
# verifying usage
if [ "$#" = "0" -o "$1" = "-h" -o "$1" = "--help" ]; then
echo Usage : $(basename $0) image [ image ... ]
echo Used to generate thumbnails of a list of images.
exit 1
fi
# loop that enables the treatment of a list of images
for i in "$@"; do
# verifying file
if [ -f "$i" ]; then
# get image infos
read itype resolution name extension size << EOF
$(identify -format "%m %wx%h %t %e %b" "$i")
EOF
# convert size to human readable format
if [ $size -ge 1048576 ]; then
sizeh="$(( size / 1048576 )) Mo"
elif [ $size -ge 1024 ]; then
sizeh="$(( size / 1024 )) Ko"
else
sizeh="$size o"
fi
# resize image and add infos
convert "$i" -resize 400x200 -gravity South -background Black -fill white -splice 0x18 -draw "text 0,2 '$itype : $resolution - $sizeh'" "$name"-thumb.$extension
else
echo "$i" : file does not exist
fi
done