I have a command line utility, let's called as: produce_image. So i can do the following in the Terminal:

$ produce_image > some.jpg
$ open some.jpg #opens Preview.app

also, I have ImageMagick installed and Xqartz too, so I can do the following:

$ produce_image | display #the display is a command from ImageMagick suite

The above opens an X11 window with the image.

Is possible achieve such image-view as with display also with Preview.app? e.g. looking for something like:

$ produce_image | Preview.app #of course, this isn't working
$ produce_image | /Applications/Preview.app/Contents/MacOS/Preview #nor this

Is possible preview the image with Preview.app without using intermediate file?

Ps: of course, I can create a command such osxdisplay

tmpfile=$(mktemp /tmp/foobar.XXXXXX)
cat - > "$tmpfile"
open "$tmpfile"
rm -f $tmpfile

and use it as

produce_image | osxdisplay

But the merit of the question is about opening images from a shell pipe without intermediate files.


Try

produce_image | open -a Preview.app -f

(To be honest, I was quite surprised to learn that this works)


This displays image data from STDIN in the terminal in iTerm 2 (https://www.iterm2.com/documentation-images.html):

cat file.png|printf "\e]1337;File=inline=1:$(base64)\a\n"

The function below displays one or more images in the terminal.

ima(){ local f;for f;do printf "\e]1337;File=inline=1:$(if [[ $f = *://* ]];then curl -Ls "$f";else cat -- "$f";fi|base64)\a\n";done;}

To display images at a maximum height of 20 rows, add ;height=20.