-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsimg
More file actions
executable file
·53 lines (39 loc) · 1.16 KB
/
bsimg
File metadata and controls
executable file
·53 lines (39 loc) · 1.16 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
#!/bin/bash
# bsimg - jzu@free.fr 2013 - WTFPL
# Replaces ggimg (Google search) while its new HTML stays undecipherable
# Searches Bing 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
IMGDIR=/tmp/img
mkdir -p "$IMGDIR"
cd /tmp
if [ $# -eq 0 ]
then
echo Usage: `basename $0` search terms 1>&2
exit 1
fi
ARGS="$*"
SEARCH==`echo "$ARGS" \
| sed -e 's/ /\+/g'`
IMAGE=`wget -O - "http://www.bing.com/images/search?q=$SEARCH" 2>/dev/null \
| sed 's/>/>\n/g' \
| grep imgurl: \
| sed -e 's/.*imgurl:.quot;//' -e 's/.quot;.*//' \
| head -1`
wget -O img-$$ "$IMAGE" 2>/dev/null
# Make it a JPEG
convert img-$$ -resize 480 "$IMGDIR/$ARGS.jpg" &> /dev/null
# Shit happens - when download fails, img-$$ is zero-sized
if [ $? -ne 0 ]
then
echo Error: \"$ARGS\" - failed to download image 1>&2
/bin/rm -f img-$$
exit
fi
# And make it a thumbnail, by the way
convert img-$$ -resize 32x32 "$IMGDIR/$ARGS".png
# Cleanup
/bin/rm img-$$