-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththumbnails.sh
More file actions
executable file
·51 lines (44 loc) · 1.21 KB
/
thumbnails.sh
File metadata and controls
executable file
·51 lines (44 loc) · 1.21 KB
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
#!/bin/bash
#
# thumbnails.sh
# =========
# Creates thumbnails.sh recursively
#
# usage: thumbnails.sh DIRECTORY [2400x1200]
SRCDIR=$1
DESTDIR=thumbnails
RESOLUTION=${2:-2400x1200}
function print_usage() {
echo "usage: $0 DIRECTORY [2400x1200]"
}
# Creates a thumbnail from a jpg file
# usage: create_thumbnail input.jpg output.jpg
function create_thumbnail() {
convert -resize $RESOLUTION $1 $2
}
# create_thumbnails recursively goes through by each file in the directory and all subdirectories and
# creates a thumbnail in a subdirectory
# usage: create_thumbnails DIR_WITH_IMAGES
function create_thumbnails() {
local parrent_dir=$(pwd)
local dir="$1"
cd "$dir"
local files=$(ls)
for f in $files
do
if [ -d $f ] && [[ $f != thumbnails ]]
then
create_thumbnails $f
elif [ -f $f ] && ([[ $f = *.jpg ]] || [[ $f = *.JPG ]])
then
if [ ! -f "$DESTDIR/$f" ]; then
mkdir -p "$DESTDIR"
echo "Creating thumbnail for: $(pwd)/$f"
create_thumbnail "$f" "$DESTDIR/$f"
fi
fi
done
cd $parrent_dir
}
if [ -z "$SRCDIR" ]; then print_usage ; exit 1; fi
create_thumbnails $SRCDIR