-
-
Notifications
You must be signed in to change notification settings - Fork 421
/
takeScreenshots
executable file
·75 lines (64 loc) · 2.68 KB
/
takeScreenshots
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
#!/usr/bin/env bash
# Produces a bunch of `cmatrix` screenshots and screencasts.
# This script requires X and the following:
#apt-get install rxvt byzanz
# NOTE We use rxvt, as we can get a screenshot without fuss (scrollbars, menu, ...),
# it is fairly simple,
# and it supports X fonts (unlike xterm and uxterm).
TERM_EMULATOR_BASE="rxvt +sb"
CAPTURES_DIR="data/img"
# Function to take a single cmatrix screenshot (takes about 3.5s to execute)
# or optionally, a screencast of choosable length.
captureCMatrix() {
CAPTURE_FILE="$1"
CMATRIX_OPTIONS="$2"
# If 0 (default if no 3rd param is given),
# we make a screenshot instead of a screencast.
SCREENCAST_DURATION="${3:-0}"
if [ "${SCREENCAST_DURATION}" -gt 0 ]
then
KILL_DELAY="$((SCREENCAST_DURATION + 1))"
CAPTURE_FILE="${CAPTURE_FILE}.gif"
else
KILL_DELAY=3
CAPTURE_FILE="${CAPTURE_FILE}.png"
fi
WINDOW_TITLE="CMatrix capture ${CAPTURE_FILE}"
# NOTE the "-PIPE" prevents output of the "Terminated: ..." message
( cmdpid=$BASHPID; ( sleep "${KILL_DELAY}"; kill -PIPE "$cmdpid" ) & exec ${TERM_EMULATOR_BASE} -name "${WINDOW_TITLE}" -title "${WINDOW_TITLE}" -e bash -c "
if [ ${SCREENCAST_DURATION} -gt 0 ]
then
# Take screencast (animated GIF)
# Get this windows X-window-info
myXwininfo=\$(xwininfo -name \"${WINDOW_TITLE}\")
# Extract location and size
read X < <(awk -F: '/Absolute upper-left X/{print \$2}' <<< \"\$myXwininfo\")
read Y < <(awk -F: '/Absolute upper-left Y/{print \$2}' <<< \"\$myXwininfo\")
read W < <(awk -F: '/Width/{print \$2}' <<< \"\$myXwininfo\")
read H < <(awk -F: '/Height/{print \$2}' <<< \"\$myXwininfo\")
# Record a screencast as gif
byzanz-record -c --delay=0 --duration=${SCREENCAST_DURATION} --x=\$X --y=\$Y --width=\$W --height=\$H "${CAPTURE_FILE}" &
else
# Take screen-shot (PNG image)
# Take screenshot in 2 seconds
( sleep 2 ; xwd -nobdrs -name \"${WINDOW_TITLE}\" -silent | xwdtopnm 2> /dev/null | pnmtopng 2> /dev/null > ${CAPTURE_FILE} ) &
fi
# Run cmatrix until the process gets killed
cmatrix ${CMATRIX_OPTIONS}
" )
}
CMD_CS="captureCMatrix"
CAPTURE_FILE_BASE="${CAPTURES_DIR}/capture_"
mkdir -p "${CAPTURES_DIR}"
# Capture a screen session ("video"/animated GIF)
${CMD_CS} "${CAPTURE_FILE_BASE}orig" "-xba" "5"
${CMD_CS} "${CAPTURE_FILE_BASE}rainbow" "-xbar" "5"
# From here on, we take several screenshots with different arguments.
${CMD_CS} "${CAPTURE_FILE_BASE}default" ""
${CMD_CS} "${CAPTURE_FILE_BASE}bold" "-b"
${CMD_CS} "${CAPTURE_FILE_BASE}bold_font" "-bx"
for color in green red blue white yellow cyan magenta black
do
${CMD_CS} "${CAPTURE_FILE_BASE}bold_C_${color}" "-b -C ${color}"
done
${CMD_CS} "${CAPTURE_FILE_BASE}bold_rainbow" "-b -r"