概述
你是否遇到过这样的情况?希望能查看服务器中的图片大致是什么样子,却只能通过终端SSH登陆服务器,而无法直接下载里面的图片到本地。本文介绍的工具Terminal Image Viewer就能在终端命令行中显示图片,原理其实就是直接用色块打印出图片的内容,由于分辨率有限,只能近似地显示图片缩略图。此工具在Github上有开源代码:https://github.com/stefanhaustein/TerminalImageViewer
安装
根据官方的介绍,先用命令安装imagemagick,再用make编译安装:
sudo apt install imagemagick || yum install ImageMagickgit clone https://github.com/stefanhaustein/TerminalImageViewer.gitcd TerminalImageViewer/src/main/cppmakesudo make install
使用
命令行中直接输入tiv即可查看使用说明:
usage: tiv [options] [...] -0 : No block character adjustment, always use top half block char. -256 : Use 256 color mode. -c : Number of thumbnail columns in 'dir' mode (3). -d : Force 'dir' mode. Automatially selected for more than one input. -f : Force 'full' mode. Automatically selected for one input. -help : Display this help text. -h : Set the maximum height to lines. -w : Set the maximum width to characters.
例如,我想查看当前目录中,一个名为n03792782_55532.JPEG的图片,执行:
tiv n03792782_55532.JPEG
![afb8a5a27b43511f6ecaa677611659ad.png](https://i-blog.csdnimg.cn/blog_migrate/a9531d1a4423c8d9b9ac8699563f9838.jpeg)
显示效果
我们可以对比一下原图:
![d702ead5ea64c094e9148925c957899f.png](https://i-blog.csdnimg.cn/blog_migrate/8fa906948179bdb770895d45e3499206.jpeg)
原图
当我们想一次显示多张图片时,可以用通配符:
tiv n03792782_555*
![3498cf76b463f67efe8d749807ff58ec.png](https://i-blog.csdnimg.cn/blog_migrate/74b5b342c589a268462475d6d4e4da08.jpeg)
显示多张图片
另外两张原图如下:
![3a289dc54a4d333382f918bacead7f55.png](https://i-blog.csdnimg.cn/blog_migrate/28666a59a4ccb1dd9a2691d416f6ea06.jpeg)
原图
![1d5103f47d9fa213cff3ce389af3af96.png](https://i-blog.csdnimg.cn/blog_migrate/7fde14d7f06864b53e8db0980cedb4f1.jpeg)
原图
从显示效果上看,文字等细节是看不清楚的,当成缩略图来看即可,掌握此工具即可在命令行中浏览图片缩略图,有需要的同学收藏起来吧。