summary refs log tree commit diff
path: root/.config/vifm/scripts/vifm-show-sixel
blob: 16441537d2736026a36f6f9f40e634f6aa51f8e9 (plain) (blame)
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
#!/bin/bash

set -e

if [ "$#" -ne 3 ]; then
    echo "Usage: $0 filename width height"
    exit 1
fi

dim=( $(convert "$1" -format "%w %h" info:) )
w=${dim[0]}
h=${dim[1]}

pw=$(($2*8))
ph=$(($3*14))

height=auto
width=auto
if [ $pw -lt $w ] && [ $ph -lt $h ]; then
    newh=$(echo "($h*$pw)/$w" | bc)
    neww=$(echo "($w*$ph)/$h" | bc)

    if [ $newh -le $ph ]; then
        width=$pw
    else
        height=$ph
    fi
elif [ $pw -lt $w ]; then
    width=$pw
elif [ $ph -lt $h ]; then
    height=$ph
fi

# debugging stuff
# echo pw=$pw ph=$ph
# echo w=$w h=$h
# echo neww=$neww newh=$newh
# exec echo width=$width height=$height

# account for GNU screen
if [ -n "$STY" ]; then
    popt=-P
fi

exec img2sixel $popt --width=$width --height=$height "$1"