sergei-grechanik / tupimage

A utility to upload and display terminal images using the unicode placeholder extension of the kitty graphics protocol
MIT No Attribution
9 stars 1 forks source link

[feat] Is it possible to displace two pics in a row? #3

Closed xuwei152 closed 1 year ago

xuwei152 commented 1 year ago

I am using this excellent tool. I am wondering if it is possible to display two pics in a row by a command like

tupimage img1.png img2.png

. It is helpful when we want to have a comparison between two pngs.

Thanks in advance.

sergei-grechanik commented 1 year ago

Unfortunately, there's currently no direct way to achieve this. However, you can redirect the placeholders to files and then use paste. You can find an example in test_uploading_script.sh:

draw_strips() {
    local i=0
    local total_cols=0
    local max_cols="$(tput cols)"
    local opts="$1"
    shift
    for file in "$@"; do
        (( i++ )) || true
        tupimage "$file" $opts --save-info "$tmpdir/info" -o "$tmpdir/tmp"
        cols="$(grep columns "$tmpdir/info" | cut -f 2)"
        if (( $total_cols + $cols > $max_cols )); then
            paste -d "" "$tmpdir/out_"*
            rm "$tmpdir/out_"*
            total_cols=0
        fi
        (( total_cols += cols )) || true
        mv "$tmpdir/tmp" "$tmpdir/out_$(printf "%02d" $i)"
    done
    paste -d "" "$tmpdir/out_"*
    rm "$tmpdir/out_"*
}

# The height of each image will be 9 rows
draw_strips "-r 9" *.png

It's a bit ugly, but it actually wraps the images correctly if they exceed the screen width.

I'm currently in the process of rewriting tupimage in python, and I will definitely include this feature, but it's going to take time.

xuwei152 commented 1 year ago

Thanks for the script. It works for me. Looking forward to the tupimage in Python.