/
lorempixel.sh
executable file
·103 lines (83 loc) · 1.99 KB
/
lorempixel.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
LOREM_PIXEL_URL='http://lorempixel.com'
WIDTH='800'
HEIGHT='600'
REPEAT='1'
DRY_RUN=false
VERBOSE='-nv'
CATEGORY='0'
URL=$LOREM_PIXEL_URL
IMAGE_NAME='image'
usage()
{
cat << EOF
usage: $0 options
This script will download an image from the lorempixel.com with set width and height.
OPTIONS:
-i Show this message
-w Width of the image, if ommited the default value of $WIDTH is used
-h Height of the image, if ommited the default value of $HEIGHT is used
-c category of the image, categories are: abstract, animals, city, food, nightlife, fashion, people, nature, sports, technics, transport
-r How many images do you need, aka how many times to repeat the process, default is $REPEAT
-v verbose mode
-d Dry run, testing purposes only
EOF
}
while getopts “itgtdtvt:w:h:r:c:” OPTION
do
case $OPTION in
help)
usage
exit 1
;;
w)
WIDTH=$OPTARG
;;
h)
HEIGHT=$OPTARG
;;
r)
REPEAT=$OPTARG
;;
c)
CATEGORY=$OPTARG
;;
g)
URL=$LOREM_PIXEL_URL'/greyscale'
IMAGE_NAME='image-greyscale'
;;
v)
VERBOSE=''
;;
d)
DRY_RUN=true
;;
?)
usage
exit
;;
esac
done
ITERATION='0'
while [ $ITERATION -lt $REPEAT ]
do
WGET_URL="$URL/$WIDTH/$HEIGHT/$CATEGORY"
WGET_IMAGE=$IMAGE_NAME
if [[ $CATEGORY != '0' ]];
then
WGET_IMAGE=$WGET_IMAGE'-'$CATEGORY
fi
WGET_IMAGE=$WGET_IMAGE'-'$WIDTH'-'$HEIGHT
if [ $REPEAT -gt '1' ];
then
WGET_IMAGE=$WGET_IMAGE'-'$[$ITERATION+1]
fi
WGET_IMAGE=$WGET_IMAGE'.jpg'
if [ $DRY_RUN == true ];
then
echo $WGET_URL' -> '$WGET_IMAGE
else
wget -O $WGET_IMAGE $WGET_URL $VERBOSE
fi
ITERATION=$[$ITERATION+1]
done