atanunq / viu

Terminal image viewer with native support for iTerm and Kitty
MIT License
2.53k stars 56 forks source link

Aspect ratio off on iTerm2 #65

Closed thorlucas closed 3 years ago

thorlucas commented 3 years ago

I've curl https://via.placeholder.com/20 -o 20.png to product a 20x20 png. Then I run viu 20.png in iTerm2.

Here are the results:

Screen Shot 2021-03-13 at 4 23 01 PM

As you can see the aspect ratio is clearly off. I suppose this has something to do line height setting? Does iTerm2 have API for polling this?

thorlucas commented 3 years ago

According to iterm2, preserveAspectRatio should be set to 1 to avoid this.

thorlucas commented 3 years ago

P.S. imgcat has the proper aspect ratio in iTerm2.

thorlucas commented 3 years ago

Ok I did some investigation. imgcat's source:

function print_image() {
    print_osc
    printf '1337;File='
    if [[ -n $1 ]]; then
        printf "name=%s;" "$(printf "%s" "$1" | b64_encode)"
    fi

    printf "%s" "$3" | b64_decode | wc -c | awk '{printf "size=%d",$1}'
    printf ";inline=%s" "$2"
    printf ":"
    printf "%s" "$3"
    print_st
    printf '\n'
    if [[ -n $4 ]]; then
        echo "$1"
    fi
}

Which evaluates to

\033]1337;File=size=165;inline=1:<the base64 encoded image>\a

It seems that viuer passing in the width and height is messing this up. I will cross post this issue to viuer since I didn't realize at first that this was an issue on that crate instead.

atanunq commented 3 years ago

Followed up in the linked viuer issue.