Linux shell script for resizing pictures for the web. Detects if the pictures are rotated and places a nametag (like your name or homepage for copyright purposes) in the south east of the picture. (Its necessary to install imagemagick first)
You can easily change image extention, image size, image type and the look of the nametag.
Here is an explanation how to use convert to make your tag even nicer:
Imagemagick annotating
Thx to kai for the help!
#!/bin/bash
# resizes all pictures according to rotation to 1024x768 or 768x1024
# places a nametag into the south east of the pictures
# copies all changed images to directory $IMAGE_DIRECTORY
IMAGE_DIRECTORY='small'
IMAGESIZE='1024x768'
IMAGESIZE_ROTATED='768x1024'
NAMETAG='www.geekpeitsche.de'
NAMETAG_LOCATION='120'
NAMETAG_COLOR='white'
IMAGE_EXTENTION='*.jpg *.JPG'
if [ ! -d $IMAGE_DIRECTORY ]; then
mkdir $IMAGE_DIRECTORY
else
echo $IMAGE_DIRECTORY exists
# exit 1
fi
# looking for all images in the current directory
for i in $IMAGE_EXTENTION;
do
# gets the size of the pictures from identify
# identify: picture information
# 1st grep: everything before the x
# 2nd grep: gets the numbers
# head: gets only the first row (somehow on my machine there is a 2 row printout - remove if necessary)
SIZEX=$(identify $i | egrep -o '[0-9]+x' | egrep -o '[0-9]+' | head -1)
SIZEY=$(identify $i | egrep -o 'x[0-9]+' | egrep -o '[0-9]+' | head -1)
# checking rotation and resizing to IMAGEHEIGHTxIMAGEWIDTH or IMAGEWIDTHxIMAGEHEIGHT
if( test $SIZEX -ge $SIZEY; ) then
convert -size $IMAGESIZE $i -resize $IMAGESIZE $IMAGE_DIRECTORY/$i;
else
convert -size $IMAGESIZE_ROTATED $i -resize $IMAGESIZE_ROTATED $IMAGE_DIRECTORY/$i;
fi
# using convert to put the nametag 'www.geekpeitsche.de' to the SouthEast of the pictures
# make the text white and place a black shadow behind the letters
convert -size $NAMETAG_LOCATION'x'14 xc:none -gravity center \
-stroke black -strokewidth 2 -annotate 0 $NAMETAG \
-background none -shadow $NAMETAG_LOCATION'x'3+0+0 +repage \
-stroke none -fill $NAMETAG_COLOR -annotate 0 $NAMETAG \
$IMAGE_DIRECTORY/$i +swap -gravity SouthEast -geometry +0-3 \
-composite $IMAGE_DIRECTORY/$i
# # # OLD VERSION
# # # using convert to put the namegag 'www.geekpeitsche.de' to the pictures
# # # convert -font helvetica -fill grey -pointsize 25 -draw 'gravity SouthEast text 5,5 $NAMETAG' $IMAGE_DIRECTORY/$i $IMAGE_DIRECTORY/$i
done