46

I'm looking for an image viewer that takes data on stdin and can be run like:

cat image.png | imageviewer
Mechanical snail
  • 7,583
  • 5
  • 45
  • 66
SL9
  • 461
  • 1
  • 4
  • 3

6 Answers6

57

ImageMagick's display program will do just that, assuming you pipe it something that it understands.

cat image.png | display

and it'll pop up a window showing that image.

erjiang
  • 747
  • 5
  • 16
  • 4
    On version `ImageMagick 6.8.8-1 Q16 i686 2014-01-04` I need to also pass `-` as a parameter: `$ cat image.png | display -` or `$ display - < image.png`. – Emil Lundberg Jan 27 '14 at 19:52
16

ImageMagick's display.

display < foo.png
Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247
8

You can use feh, it's pretty fast.

cat image.png | feh --scale-down -  

feh is a lightweight image viewer which is in the default repositories of many Linux distributions. It is especially aimed at command line users who need a fast image viewer without huge GUI dependencies.

karel
  • 13,390
  • 26
  • 45
  • 52
MaikoID
  • 274
  • 4
  • 10
  • 3
    Can you expand your answer a bit? Just mentioning a product (is that a command, product, or an expression of indifference?), doesn't really explain how to accomplish the solution. It's better to explain how to use the product to solve the problem, or at least describe what makes the product a good solution, not just a random Google hit. Good guidance on recommending software here: http://meta.superuser.com/questions/5329/how-do-i-recommend-software-in-my-answers. Thanks. – fixer1234 Aug 23 '16 at 22:16
  • 4
    The question is very specific, I gave a specific answer. And for god sake there is a command line right above us. – MaikoID Aug 24 '16 at 15:26
8

On Linux (and likely BSDs), almost all of them – if you give /dev/stdin as the path. This includes: xloadimage, feh, Eye of GNOME (eog).

eog /dev/stdin < "$file"

(Not all of them work well with special files, though. GThumb failed the test, for example.)

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 4
    This doesn't work: cat graph.png | eog /dev/stdin – bukzor Apr 13 '11 at 16:03
  • If we know "$file", i think we can issue eog "$file".Am I missing something? – Naga Kiran Jun 20 '11 at 18:27
  • 5
    @Naga: The `< "$file"` was an example. The point was whether the program can accept an arbitrary stream, be it a simple redirection or something more advanced (such as providing an image via stdin, a named pipe, process substitution, a socket, or a character device). The problem is that many viewers require the fd to be seekable, which only regular files and block devices are. – u1686_grawity Jun 20 '11 at 18:56
  • 3
    As @bukzor pointed out, `cat graph.png | eog /dev/stdin` fails, but `eog /dev/stdin < graph.png` works. – Denilson Sá Maia Jan 03 '12 at 17:18
  • 2
    Is there any way to make this method work with piping (`|`) as well? – Tarrasch May 12 '12 at 16:05
  • 2
    It looks like `eog` is looking up information on the file descriptor (which succeeds in the special case that it was redirected directly from a file), whereas normal Unix programs will just take the input regardless of where it comes from. So `eog` won't work for general stdin. Another program that works is `gwenview /dev/stdin` (the KDE image viewer). – Mechanical snail Mar 04 '14 at 04:13
  • As MaikoID's answer shows, `... | feh -` works. But `... | feh /dev/stdin` fails. – Camille Goudeseune Feb 23 '17 at 22:13
  • `eog <(cat file.png)` – Tom Hale Jul 15 '20 at 14:03
4

A FIFO could work with eog's lack of piping support:

mkfifo ${tmpfilename};
cat ${file} > ${tmpfilename} &;
eog /dev/stdin < ${tmpfilename};
rm ${tmpfilename};

AFAIK this should work.

Nathan Ringo
  • 153
  • 6
0

With imv, e.g. on Debian bullseye:

sudo apt install imv

# it provides commands imv-x11 and imv-wayland
# e.g. with imv-x11, pipe to imv-x11, and make sure to end the command with a dash: e.g.

systemd-analyze plot | imv-x11 -

# "systemd-analyze plot" returns on stdout an SVG image of the systemd services/units startup timeline
Abdull
  • 2,046
  • 4
  • 19
  • 24