How to continuously display the newest version of an image file on Linux?

I need program that reads an image from the disk location /home/me/image.png, displays it on the screen in a window and then refreshes the window whenever there is a change to the image located at /home/me/image.png.

My preferred program for viewing images is feh but feh does not have a built-in feature for refreshing itself when the file changes.

One option I considered was writing bash script that kills and reopens feh whenever the file changes. But that would display the image in a new window. I want to display the image in its original window.

I tried ImageMagick’s display utility but it doesn’t work on my machine. Maybe I’m using display wrong? I used $ display -update 1 /home/me/image.png. ImageMagick doesn’t give me any errors. It just fails to refresh the image when I write changes to disk.

Refreshing an image when it changes on disk seems like a basic feature lots of image-viewing programs ought to support, but I’ve tried several image-viewing programs like feh, fim and eog but none of them refresh when the image on disk changes.

System Specs

My shell is bash. My windowing system is i3. My distro is lubuntu.

Asked By: lsusr

||

sxiv is a simple X image viewer that automatically reloads an image when it is modified. It does not require any special options. Simply launch an image using:

sxiv <file>

It is available in the Ubuntu repositories under the package name sxiv.

Answered By: Stephan

It’s a little involved, but you can build a version of feh that supports --auto-reload using the Ubuntu / Debian tools. I don’t know why this isn’t enabled by default, frankly.

Install any packages needed to build feh: sudo apt-get build-dep feh

Install the package building support: sudo apt-get install build-essential devscripts

Make a directory to work in: mkdir src && cd src

Get the upstream source: apt source feh

Chdir with cd feh-3.6.3 or to whichever directory you have

Edit the debian/rules file to change this line:

dh_auto_build --parallel -- PREFIX=/usr exif=1

To:

dh_auto_build --parallel -- PREFIX=/usr exif=1 inotify=1

Build the package: debuild -us -uc -b. You can ignore most warnings and even some errors.

Install your shiny new feh package: sudo dpkg -i ../feh_3.6.3-1_amd64.deb

Now you will have a feh --auto-reload option that will automatically reload a file if it changes on disk. And unlike eog or eom, it will cope with partial or broken files, so if you’re updating the file non-atomically (e.g. streaming an image processing program’s output to a file) then it won’t break and stop showing the file.

You’ll probably want to make sure feh isn’t accidentally upgraded by apt – to do this, mark it as "held" with:

sudo apt-mark hold feh

You can unmark it in future, should you wish to upgrade to the distro’s upstream version, with:

sudo apt-mark unhold feh

Answered By: davidA
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.