Need a Linux solution for looped slideshow from pictures in some folder. Pictures may be deleted and added, so it's a bonus if it doesn't stop/crash if currently shown picture is deleted.
8 Answers
This is going to sound crazy, but it works (better than I expected even) and is not that hard to setup. The idea is to make your viewing program look at a single file and then have a command line process that copies each of your files in your directory to that file you view. I tested this with Geeqie and gthumb and it actually works pretty well. gthumb even can handle the image being updated every second and both supported the name of the file type being different from the actual file type (jpg, png, gif, etc).
So here is what you do:
- Make a directory with only your pictures in them.
- open a terminal window and change to the directory made in the previous step.
Run this command, substituting 5 with however many seconds you want to wait in between updates.
while true ; do for i in * ; do cp "$i" ~/slideshow.jpg ; echo $i ; sleep 5 ; done ; done
Open gthumb and view the image in your home directory called slideshow.jpg, it should rotate the picture. You can make gthumb full screen now if you need to.
Try adding and removing pictures from the picture directory. It won't actually update until its finished going through the whole directory each time, but it will update. The echo $i is in there just so you can see what picture it just copied into place each time.
When you are ready to stop the slideshow, you can press Ctrl-C in the terminal window.
-
1Brilliant. It takes a genius to understand the simplicity. Commented Nov 20, 2010 at 13:24
If you use Gnome desktop, then you can use its official image viewer program for slide shows:
eog --slide-show /path/to/picture_directory
With Eog pictures can be removed or added during the slide show. Actually, if you add picture during the slide show, it will be automatically included.
-
-
1Using this on my Raspberry Pi, I was not able to add or remove files without restarting the slideshow. Not a criticism, just FYI.– ButtersCommented Mar 25, 2014 at 16:21
-
1
-
1On Ubuntu 16.04 using XFCE desktop, this worked but, while most UI elements were polished (fade-in and out, etc), an unwelcome menu bar was visible at the top at all times, even in full-screen slideshow mode. This will not be acceptable for every use. Commented May 6, 2018 at 6:51
-
I second Butters, this did not work on Raspbian. The added pictures never show up, and removed pictures generate errors from EOG. Perhaps this is due to the fact I'm reading from a rclone'd folder (from Google drive), but either way it does not work in some circumstances. Commented Oct 21, 2020 at 17:45
From http://www.instructables.com/id/Easy-Raspberry-Pi-Based-ScreensaverSlideshow-for-E/
using feh
feh -Y -x -q -D 5 -B black -F -Z -z -r /media/
-
3You also need to add the option
-R seconds
so that the file list is refreshed periodically.– famzahCommented Dec 28, 2018 at 21:15 -
1You might also want to add
--auto-rotate
to rotate images correctly based on EXIF data. Commented Oct 9, 2019 at 10:40
Impressive does the job well, with (or without if you wish) transitions.
Slideshow in random (-X
) order with 3 seconds delay (-a 3
) and autoquit at the end (-Q
) :
impressive -XQa3 *
It's worth noticing that it allows scripting, and is multiplatform.
The only drawback is that it currently crashes if there is a directory in the list of files.
-
1
-
1If only it allowed to auto-rotate images based on EXIF data. Did not find any option to do this. :( Commented Oct 9, 2019 at 10:48
I found fbi (frame buffer image viewer) quite useful- Simple command, something like :
fbi -noverbose -a -u -t 6 /home/user/location/*
More options available withfbi --help
and can be installed, depending on distro with apt-get install fbi
-
-
1
-
You'll probably have to specify a particular tty, using
-T 2
for example to selecttty2
. You'll probably have to muck around with permissions after that. Commented Apr 5, 2018 at 18:27 -
Does not work from command line on current Raspbian with screen attached :( Also seems to be lacking EXIF-based auto-rotate feature (I read). Commented Oct 20, 2019 at 21:57
The best Linux solution for me is feh
sudo apt install feh
feh -rzsZFD 5 /home/my_folder
It has many options, in this case it will show recursively a random picture from my_folder (and its subfolders) every 5 seconds.
I looked at many different solutions to this problem, including fbi, feh, and more.
I ended up using pygame of all things. This may not be clean, ideal, or optimal, but it does the job, it provides quick changes between slides without a long dark space between (fbi does this if you needed it to exit and restart to vary the timing between slide changes as is my case). Nonetheless, it is running (tested, deployed) code. As an added advantage, this code appears to be impossible to break out of into a shell and appears to be safe to run from .bashrc on an autologin. (This is added safety on a system that has no keyboard).
If you change the slide list and/or timing in the configuration file, you'll need to restart the script for changes to take effect. If you just replace the existing slide files, the changes will be picked up at the next slide change.
import pygame
import sys
import time
import os
import re
# Initialize the display
#pygame.init()
os.environ['SDL_NOMOUSE'] = '1'
pygame.display.init()
pygame.mouse.set_visible(False)
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
black = 0, 0, 0
print("Obtained screen dimensions (", size, ")")
screen = pygame.display.set_mode(size, flags=pygame.HWSURFACE|pygame.DOUBLEBUF)
# Get the slide show data
LIST = open(os.environ['HOME']+"/data_dir/slide_order.txt","r")
slides = []
for line in LIST:
line = line.rstrip('\r\n')
if (re.match('^[\w\d\. ]+\t+\d+$', line)):
(fn, duration) = re.split('\t+', line)
duration = int(duration)
print("Adding file:", fn, "for", duration, "seconds")
slides.append([fn, duration])
LIST.close()
while True:
for (index, values) in enumerate(slides):
print("Retrieved (",values,") at index:",index)
(fn, duration) = values
print("Loading image")
image = pygame.image.load(os.environ['HOME']+"/data_dir/"+fn)
print("Scaling image")
image = pygame.transform.scale(image, size)
irect = image.get_rect()
print("Clearing buffer")
screen.fill(black)
print("BLIT")
screen.blit(image, irect)
print("Display Image")
pygame.display.flip()
print("Sleeping...")
time.sleep(duration)
print("Awake")
sys.exit(0)
So I found deltaray's answer really genius and I just wanted to expand on a script I have been using that takes from their answer. The script right now exhaustively without repeats selects from the current working directory a random image while skipping over the script if selected, then applies deltaray's answer. Here is the script.
#!/bin/bash
selected_indices=()
function select_random_file() {
local files=(*)
local count=${#files[@]}
if (( count > 0 )); then
local random_index=$(( RANDOM % count ))
# Check if the index has been selected before
while [[ "${selected_indices[@]}" =~ $random_index ]]; do
random_index=$(( RANDOM % count ))
done
# Add the index to the selected_indices array
selected_indices+=($random_index)
local random_file=${files[random_index]}
echo "$random_file"
else
echo "No files found in the current directory."
fi
}
while true; do
selected_file=$(select_random_file)
cp "$selected_file" ~/slideshow.jpg
echo "$selected_file"
sleep 30
done