-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathggimg
More file actions
executable file
·54 lines (41 loc) · 1.1 KB
/
ggimg
File metadata and controls
executable file
·54 lines (41 loc) · 1.1 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
52
53
54
#!/bin/bash
# ggimg - jzu@free.fr 2013 - WTFPL
# Searches Google Images using the parameter as search terms
# Grabs the first one to appear
# Normalizes its size to 480 pixels wide
# Gives it the name of the search terms + .jpg
# Creates a 32x32 thumbnail (e.g. to insert in FLAC files)
# Needs wget and ImageMagick
if [ $# -eq 0 ]
then
echo Usage: `basename $0` search terms 1>&2
exit 1
fi
SEARCH="$*"
(
echo "$SEARCH" \
| sed -e 's/ /\+/g' \
-e 's/^/\"http:\/\/www.google.com\/search\?tbm=isch\&q=/' \
-e 's/$/"/' \
| xargs wget -nv -O - -U "Firefox/3.0.15" \
| sed 's/>/>\n/g' \
| grep -B 1 '<img' \
| head -1 \
| sed -e "s/.*imgurl=//" \
-e "s/.amp;.*//" \
-e "s/%3F.*//" \
| xargs wget -nv -U "Firefox/3.0.15" -O "img-$$"
) &> /dev/null
# Make it a JPEG
convert img-$$ -resize 480 "$SEARCH.jpg" &> /dev/null
# Shit happens - when download fails, img-$$ is zero-sized
if [ $? -ne 0 ]
then
echo Error: \"$SEARCH\" - failed to download image
/bin/rm -f img-$$
exit
fi
# And make it a thumbnail, by the way
convert img-$$ -resize 32x32 "$SEARCH.png"
# Cleanup
/bin/rm img-$$