一款能在终端命令行中查看图片的工具——Viu

同样的在那时候亦是发现另外一款差不多功能的软件可供选择,其中在后续的使用中发现 tiv 这款工具无法播放 GIF 动图,只能显示某一帧的静态图像,而后续的使用中发现 viu 这款软件支持播放 GIF 动图。

起初还不咋了解这一个工具来着,看着有些繁杂的样子就没有打算安装。直至到后面在研究将录制的步骤转换成 GIF 动图的时候,无意中给安装了 RUST 工具链—— Cargo 环境,至此转动图的没能成功就干脆安装看到的这个吧。

描述

一个小型命令行应用程序,用于查看用 Rust 编写的终端图像。它基本上是 Viuer 的前端。如果支持,它使用 iTerm 或 Kitty 图形协议。 如果没有,则显示下半块(\u2584)。

安装及使用

  1. 安装 Rust 工具链(如果未安装)
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs  | sh
    source $HOME/.cargo/env
    
    
  2. 使用Cargo安装viu
    cargo install 
    
  3. 验证是否安装成功
    viu --help
    

    应该显示版本号,例如:、

    viu 1.6.1
    
  4. 浏览图片

    浏览单张图片:

    viu demo.jpg
    

    浏览目录下的图片:

    viu -r ./images
    

其他安装方法

源码安装

源码安装需要本地的 Rust 环境。

git clone https://github.com/atanunq/viu.git

# 编译并安装
cd viu/
cargo install --path .

# 使用
viu demo.gif

二进制文件

可从 Github 发布版本下载预编译的二进制文件进行安装,通过这种方法安装就无需 Rust 环境即可正常使用。例如:

wget https://github.com/atanunq/viu/releases/download/v1.6.1/viu-x86_64-unknown-linux-musl
mv viu-x86_64-unknown-linux-musl /usr/local/bin/viu
chmod +x /usr/local/bin/viu

查看当前版本:

root@ChiuYut-VM:~# viu --version
viu 1.6.1

macOS

brew install viu

Arch Linux

pacman -S viu

题外话

使用中发现其也是在终端命令行界面下显示照片的,静态图片会直接一次性输出到终端,而 GIF 动图则会还在“交互式”的状态下显示并播放,Ctrl-C停止运行后动图就不会再继续播放动图了。

附上软件帮助:

root@ChiuYut-VM:~# viu --help
View images right from the terminal.

Usage: viu [OPTIONS] [file]...

Arguments:
  [file]...  The images to be displayed. Set to - for standard input.

Options:
  -w, --width <width>                   Resize the image to a provided width
  -h, --height <height>                 Resize the image to a provided height
  -x <x>                                X offset [default: 0]
  -y <y>                                Y offset [default: 0]
  -a, --absolute-offset                 Make the x and y offset be relative to the top left terminal corner. If not set, they are relative to the cursor's position.
  -r, --recursive                       Recurse down directories if passed one
  -b, --blocks                          Force block output
  -n, --name                            Output the name of the file before displaying
  -c, --caption                         Output the name of the file after displaying
  -t, --transparent                     Display transparent images with transparent background
  -f, --frame-rate <frames-per-second>  Play the gif at a given frame rate
  -1, --once                            Loop only once through the gif
  -s, --static                          Show only the first frame of the gif
  -H, --help                            Print help information
  -V, --version                         Print version

viu浏览静态图:

viu浏览静态图

viu浏览动态图:

viu浏览动态图

参考

  • rustuphttps://rustup.rs/
  • Terminal image viewer with native support for iTerm and Kittyhttps://github.com/atanunq/viu

ChiuYut

2026年05月08日

发布者

ChiuYut

咦?我是谁?这是什么地方? Ya ha!我是ChiuYut!这里是我的小破站!