-
Notifications
You must be signed in to change notification settings - Fork 4
/
waterMark
executable file
·68 lines (59 loc) · 1.67 KB
/
waterMark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
##---
# Julien Lengrand-Lambert
# Created on : Sat Jun 11 22:15:32 CEST 2011
#
# DESCRIPTION : Script designed to automatically watermark all the images in a folder given a template. Resize images at the same time to make them fit with Piwigo's desires.
# EXAMPLE : ./waterMark in_folder out_folder watermark_image
#
# IMAGEMAGICK COMMANDS:
# identify -format "%w,%h"foto.jpg
# composite -gravity SouthWest -geometry +5+5 -size 2000x2000 site.png foto_new.jpg test.jpg
# convert -resize 1024 foto.jpg foto_new.jpg
##---
# Check whether imagemagick is installed
hash identify 2>&- || { echo >&2 "imagemagick is required to use this script! Aborting."; exit 1; }
IN_REPO=$1
OUT_REPO=$2
WATER=$3
echo " Input repo is : $IN_REPO"
# creating output folder
mkdir -pv $OUT_REPO
SAVEIFS=$IFS # used to take care of files with spacenames
IFS=$(echo -en "\n\b")
for file in $IN_REPO/*
do
HEIGHT=$(identify -format "%h" ${file})
WIDTH=$(identify -format "%w" ${file})
#echo "w: $WIDTH , h:$HEIGHT"
BASEFILE=$(basename $file)
#DIRFILE=$(dirname $file)
OUTNAME="$OUT_REPO/$BASEFILE"
#echo "OUT : $OUTNAME"
#echo "dir : $DIRFILE, base : $BASEFILE"
#checking wether we are in portrait or lanscape mode
#---
if [ $WIDTH -ge $HEIGHT ]
then
echo "image $file is in landscape mode !"
#resizing
DIM="1024"
GRAV="SouthWest"
#---
elif [ $HEIGHT -gt $WIDTH ]
then
echo "Image $file is in portrait mode !"
DIM="x1024"
GRAV="NorthWest"
#---
else
echo "Unknown problem with file $file. Image not processed !"
continue
fi
#---
#resizing
convert -resize $DIM $file $OUTNAME
composite -gravity $GRAV -geometry +10+10 $WATER $OUTNAME $OUTNAME
done
IFS=$SAVEIFS
exit 0