forked from binRick/ansi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_rgb_image.sh
executable file
·39 lines (32 loc) · 1015 Bytes
/
get_rgb_image.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
#!/usr/bin/env bash
set -eou pipefail
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HEIGHT=5
icat="kitty +kitten icat"
R=${1:-100}
G=${2:-100}
B=${3:-100}
VIEW=${4:-0}
RESIZE=${RESIZE:-1}
RESIZE_WIDTH=${RESIZE_WIDTH:-40}
RESIZE_HEIGHT=${RESIZE_HEIGHT:-20}
PNG=pngs/color-$R-$G-$B.png
PNG_RESIZED=pngs/color-resized-$R-$G-$B-${RESIZE_WIDTH}x${RESIZE_HEIGHT}.png
ANS=pngs/color-$R-$G-$B.ansi
if [[ ! -f $ANS ]]; then
for x in $(seq 1 $HEIGHT); do
ansi -n --bg-rgb=$R,$G,$B " " >>$ANS
done
fi
[[ -f "$PNG" ]] || ansi2png --png --xsize 30 --ysize $HEIGHT $ANS $PNG 2>/dev/null
resize() {
[[ -f "$PNG" ]] && [[ ! -f "$PNG_RESIZED" ]] && magick -extract ${RESIZE_WIDTH}x${RESIZE_HEIGHT}+0+0 $PNG $PNG_RESIZED
true
}
if [[ "$RESIZE" == 1 ]]; then
resize
[[ -f "$PNG_RESIZED" ]] && [[ "$VIEW" == 1 ]] && $icat $PNG_RESIZED || echo -e "$(pwd)/$PNG_RESIZED"
else
[[ -f "$PNG" ]] && [[ "$VIEW" == 1 ]] && $icat $PNG || echo -e "$(pwd)/$PNG"
fi
true