-
Notifications
You must be signed in to change notification settings - Fork 74
/
crawl_thumbnail.sh
executable file
·33 lines (29 loc) · 1.05 KB
/
crawl_thumbnail.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
#! /bin/sh
if [ $# -ne 2 ]; then
echo "usage: $0 url ID" >&2
exit 1
fi
BIN=wkhtmltoimage
ROOT=`dirname "$0"`
case `uname -a` in
Darwin*)
#BIN=$ROOT/wkhtmltoimage-mac
TIMEOUT=gtimeout
RUN=
OPTIONS=
;;
*)
#BIN=$ROOT/wkhtmltoimage-amd64
TIMEOUT=timeout
RUN="xvfb-run --auto-servernum --server-args=\"-screen 0, 1024x768x24\""
OPTIONS="--use-xserver"
;;
esac
make_thumb() {
convert "$1" -resize "$3^" -gravity North -crop "$3"+0+0 "$2"
if [ ! -z "$4" ]; then
convert "$2" "$4" -compose over -composite "$2"
fi
}
CMD="($TIMEOUT 60 $RUN \"$BIN\" --height 768 $OPTIONS --javascript-delay 30000 \"$1\" /tmp/$2-orig.png || $TIMEOUT 60 $RUN \"$BIN\" --height 768 $OPTIONS --disable-javascript \"$1\" /tmp/$2-orig.png || test -f /tmp/$2-orig.png) && make_thumb /tmp/$2-orig.png /tmp/$2-240x180.png 240x180 \"$ROOT/app/assets/images/hn-mask-240x180.png\" && make_thumb /tmp/$2-orig.png /tmp/$2-600x315.png 600x315 \"$ROOT/app/assets/images/hn-mask-600x315.png\" && make_thumb /tmp/$2-orig.png /tmp/$2.png 100x100"
eval $CMD