-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshowimg
executable file
·44 lines (40 loc) · 1.01 KB
/
showimg
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
#! /bin/sh
width=
height=
pAR=
while case "$1" in
-w|-width) width=";width=$2"
shift; shift;;
-h|-height) height=";height=$2"
shift; shift;;
-fit) pAR=";preserveAspectRatio=0"
shift;;
*) false;;
esac
do true
done
case "$*" in
"") echo "Usage: `basename $0` [-w WIDTH] [-h HEIGHT] [-par] IMAGE [...]" >&2
echo >&2
echo "This script outputs images to the terminal for display." >&2
echo "Parameters:" >&2
echo " -w, -width N width in N cell units, or Npx, or N%" >&2
echo " -h, -height N height in N cell units, or Npx, or N%" >&2
echo " -fit with both width and height: do not preserve aspect ratio" >&2
exit;;
esac
case "$BASH" in
?*) echo=echo;;
*) echo=/bin/echo;;
esac
for img in "$@"
do
if [ -r "$img" ]
then
#eval $(file "$img" | sed -e 's/.*, *\([0-9]*\) *x *\([0-9]*\).*/width=\1px; height=\2px/')
$echo -en "\e]1337;File=name=$(echo "$img" | base64 -w 0);inline=1"
$echo -en "${width}${height}${pAR}:$(base64 -w 0 "$img")\a"
else
echo cannot read file "$img" >&2
fi
done