从命令行查看Linux机器上的图片

2017-11-05|Categories: External cmd, Linux, macOS|

随着博客上的图片越来越多,仅仅使用WordPress来管理是不够的,有时候必须从命令行查看图片,以下是一些可用的工具。

需要X window支持的工具

如果Linux安装了X,可以使用以下工具。

eog

eog是Gnome默认的图片查看工具,使用非常简单:

eog sample.jpg

feh

feh is an X11 image viewer aimed mostly at console users. Unlike most other viewers, it does not have a fancy GUI, but simply displays images. It is controlled via commandline arguments and configurable key/mouse actions.

https://feh.finalrewind.org/

网上评价非常高,如果安装了X window可以尝试。

ImageMagick display命令

Use the display program to display an image or image sequence on any X server.

https://www.imagemagick.org/script/display.php

ImageMagick是强大的命令行图形处理工具包,只要安装了就包含display

# CentOS发行版自带,安装非常简单
yum install ImageMagick

ImageMagick identify命令 2018-04-05

identify可以查看图片元数据

# `-verbose`选项可以显示更详细的信息
$ identify /usr/share/pixmaps/faces/fish.jpg
/usr/share/pixmaps/faces/fish.jpg JPEG 96x96 96x96+0+0 8-bit DirectClass 3.23KB 0.000u 0:00.000

不需要X window支持的工具

Linux机器通常是作为服务器运行,一般不会安装X window,因此前面的工具无法运行。

Links文本浏览器

http://links.twibright.com/features.php

# 来自EPEL源
yum install -y links

2018-04-05更新:之前搞错了,Links显示图片同样需要X window

Builtin image display for GIF, JPEG, PNG, XBM, TIFF in graphics mode

Links runs in graphics mode (mouse required) on X Window System (UN*X, Cygwin)

libcaca/cacaview/caca-utils

Being able to view pictures in ASCII … The images produced sometimes are a bit unreadable, if compared to the original graphics … Viewing in console / terminal images on GNU / Linux is possible thanks to a library called libcaca.

In Debian, Ubuntu and other deb Linux distros viewing GUI images with no need for Xserver or any kind of window manager in plain ASCII is possible with cacaview.

cacaview is part of a package called caca-utils.

http://www.pc-freak.net/blog/viewing-jpeggif-and-png-in-ascii-with-cacaview-on-gnu-linux-short-review-on-caca-utils-text-mode-graphics-utilities/

用ASCII显示图片,缺乏实用性

imgcat from iTerm2 2018-04-23

imgcat就是我一直在寻找的终极解决方案

用法:

imgcat filename [filename...]

效果图:

imgcat是一个Shell脚本,短小精悍,属于iTerm2 Utilities Package(iTerm2工具包),从命令的名字就能知道它的用途:

The imgcat program displays images inline in your terminal. It supports all standard image formats, including animated GIFs.

https://www.iterm2.com/documentation-utilities.html

imgcat 只需要base64awkwccurl这四个命令即可正常工作,而这几个命令都是Linux系统的标配,所以 安装很简单,在安装了iTerm2的前提下

从其它带有图形界面的机器查看

scp

通过scp命令,把服务器图片下载到本地,用本地电脑安装的图片查看软件来查看。这样做效率很低。

sftp

通过sftp客户端,把服务器图片传送到本地,用本地电脑安装的图片查看软件来查看。比scp直观、高效,也是目前我认为最好的方式

Leave A Comment