techtonia
Posts: 2
Joined: Sat Oct 01, 2016 10:37 pm

creating slideshow of images on RaspberryPi3 with Python3

Sat Oct 01, 2016 10:59 pm

Hello and thank you in advance for help in this forum!

I am very new to Python 3 Programming - and the Raspberry Pi3 that I just got. I would like to make a simple slide show of images that will be triggered by a capture image from the Pi Camera. (I just successfully saw live video from my PiCamera through simple Python script on my Raspberry Pi3 today - very exciting!) BUT ... I have not found Python code on-line to make a simple slide show of still images. So, I have a few questions related to this:
1. Can I create a slide show of images using Python 3 without using/installing additional software?
2. Is there any code that is accessible on-line to help do this?
3. Can I use a Picamera "capture" image to trigger this slide show?
I suspect I will have more questions as I further explore Python and Raspberry Pi 3 ... so thanks for any help to get me started.

Thanks so much!
Techtonia

tom.slick
Posts: 190
Joined: Wed Jan 06, 2016 9:23 pm

Re: creating slideshow of images on RaspberryPi3 with Python

Mon Oct 03, 2016 8:30 am

techtonia wrote:Hello and thank you in advance for help in this forum!

I am very new to Python 3 Programming - and the Raspberry Pi3 that I just got. I would like to make a simple slide show of images that will be triggered by a capture image from the Pi Camera. (I just successfully saw live video from my PiCamera through simple Python script on my Raspberry Pi3 today - very exciting!) BUT ... I have not found Python code on-line to make a simple slide show of still images. So, I have a few questions related to this:
1. Can I create a slide show of images using Python 3 without using/installing additional software?
2. Is there any code that is accessible on-line to help do this?
3. Can I use a Picamera "capture" image to trigger this slide show?
I suspect I will have more questions as I further explore Python and Raspberry Pi 3 ... so thanks for any help to get me started.

Thanks so much!
Techtonia
1. Yes/No/Maybe, it depends on what you already have installed. With Python3 and Pillow (the version on pypi) you can create a slideshow easily.

2. Yes, just google "python slideshow" without the quotes and you will get About 559,000 results (0.22 seconds). The first 10 should be enough
Here is a modified example from one of the results, it's more flexible the the original, but close, (you don't need to allocate the memory for every image up front).

Code: Select all

#!/usr/bin/env python3
"""Display a slideshow from a list of filenames"""

import os
import tkinter

from itertools import cycle
from PIL import Image, ImageTk


class Slideshow(tkinter.Tk):
    """Display a slideshow from a list of filenames"""
    def __init__(self, images, slide_interval):
        """Initialize
        
        images = a list of filename 
        slide_interval = milliseconds to display image
        """
        tkinter.Tk.__init__(self)
        self.geometry("+0+0")
        self.slide_interval = slide_interval
        self.images = None
        self.set_images(images)
        self.slide = tkinter.Label(self)
        self.slide.pack()

    def set_images(self, images):
         self.images = cycle(images)

    def center(self):
        """Center the slide window on the screen"""
        self.update_idletasks()
        w = self.winfo_screenwidth()
        h = self.winfo_screenheight()
        size = tuple(int(_) for _ in self.geometry().split('+')[0].split('x'))
        x = w / 2 - size[0] / 2
        y = h / 2 - size[1] / 2
        self.geometry("+%d+%d" % (x, y))

    def set_image(self):
        """Setup image to be displayed"""
        self.image_name = next(self.images)
        filename, ext = os.path.splitext(self.image_name)
        self.image = ImageTk.PhotoImage(Image.open(self.image_name))
        
    def main(self):
        """Display the images"""
        self.set_image()
        self.slide.config(image=self.image)
        self.title(self.image_name)
        self.center()
        self.after(self.slide_interval, self.start)
    
    def start(self):
        """Start method"""
        self.main()
        self.mainloop()


if __name__ == "__main__":
    slide_interval = 2500
    
    # use a list
    #images = ["image1.jpg",
              #"image2.jpeg",
              #"/home/pi/image3.gif",
              #"/home/pi/images/image4.png",
              #"images/image5.bmp"]
    
    # all the specified file types in a directory 
    # "." us the directory the script is in.
    # exts is the file extentions to use.  it can be any extention that pillow supports
    # http://pillow.readthedocs.io/en/3.3.x/handbook/image-file-formats.html
    import glob
    images = glob.glob("*.jpg")
    path = "."
    exts = ["jpg", "bmp", "png", "gif", "jpeg"]
    images = [fn for fn in os.listdir(path) if any(fn.endswith(ext) for ext in exts)]

    # start the slideshow
    slideshow = Slideshow(images, slide_interval)
    slideshow.start()
3. It's a lot more work, but you can. It depends on what you do and how you do it. The posted example is just an example of a slideshow not what you will be using in your end code.

techtonia
Posts: 2
Joined: Sat Oct 01, 2016 10:37 pm

Re: creating slideshow of images on RaspberryPi3 with Python

Thu Oct 06, 2016 3:00 am

tom.slick wrote:
techtonia wrote:Hello and thank you in advance for help in this forum!

I am very new to Python 3 Programming - and the Raspberry Pi3 that I just got. I would like to make a simple slide show of images that will be triggered by a capture image from the Pi Camera. (I just successfully saw live video from my PiCamera through simple Python script on my Raspberry Pi3 today - very exciting!) BUT ... I have not found Python code on-line to make a simple slide show of still images. So, I have a few questions related to this:
1. Can I create a slide show of images using Python 3 without using/installing additional software?
2. Is there any code that is accessible on-line to help do this?
3. Can I use a Picamera "capture" image to trigger this slide show?
I suspect I will have more questions as I further explore Python and Raspberry Pi 3 ... so thanks for any help to get me started.

Thanks so much!
Techtonia
1. Yes/No/Maybe, it depends on what you already have installed. With Python3 and Pillow (the version on pypi) you can create a slideshow easily.

2. Yes, just google "python slideshow" without the quotes and you will get About 559,000 results (0.22 seconds). The first 10 should be enough
Here is a modified example from one of the results, it's more flexible the the original, but close, (you don't need to allocate the memory for every image up front).

Code: Select all

#!/usr/bin/env python3
"""Display a slideshow from a list of filenames"""

import os
import tkinter

from itertools import cycle
from PIL import Image, ImageTk


class Slideshow(tkinter.Tk):
    """Display a slideshow from a list of filenames"""
    def __init__(self, images, slide_interval):
        """Initialize
        
        images = a list of filename 
        slide_interval = milliseconds to display image
        """
        tkinter.Tk.__init__(self)
        self.geometry("+0+0")
        self.slide_interval = slide_interval
        self.images = None
        self.set_images(images)
        self.slide = tkinter.Label(self)
        self.slide.pack()

    def set_images(self, images):
         self.images = cycle(images)

    def center(self):
        """Center the slide window on the screen"""
        self.update_idletasks()
        w = self.winfo_screenwidth()
        h = self.winfo_screenheight()
        size = tuple(int(_) for _ in self.geometry().split('+')[0].split('x'))
        x = w / 2 - size[0] / 2
        y = h / 2 - size[1] / 2
        self.geometry("+%d+%d" % (x, y))

    def set_image(self):
        """Setup image to be displayed"""
        self.image_name = next(self.images)
        filename, ext = os.path.splitext(self.image_name)
        self.image = ImageTk.PhotoImage(Image.open(self.image_name))
        
    def main(self):
        """Display the images"""
        self.set_image()
        self.slide.config(image=self.image)
        self.title(self.image_name)
        self.center()
        self.after(self.slide_interval, self.start)
    
    def start(self):
        """Start method"""
        self.main()
        self.mainloop()


if __name__ == "__main__":
    slide_interval = 2500
    
    # use a list
    #images = ["image1.jpg",
              #"image2.jpeg",
              #"/home/pi/image3.gif",
              #"/home/pi/images/image4.png",
              #"images/image5.bmp"]
    
    # all the specified file types in a directory 
    # "." us the directory the script is in.
    # exts is the file extentions to use.  it can be any extention that pillow supports
    # http://pillow.readthedocs.io/en/3.3.x/handbook/image-file-formats.html
    import glob
    images = glob.glob("*.jpg")
    path = "."
    exts = ["jpg", "bmp", "png", "gif", "jpeg"]
    images = [fn for fn in os.listdir(path) if any(fn.endswith(ext) for ext in exts)]

    # start the slideshow
    slideshow = Slideshow(images, slide_interval)
    slideshow.start()
3. It's a lot more work, but you can. It depends on what you do and how you do it. The posted example is just an example of a slideshow not what you will be using in your end code.
THANKS so much, Tom! I will try this script. And ... let you know how I do. Have a nice evening! Later, Techtonia!

sten
Posts: 1
Joined: Thu Apr 26, 2018 2:24 pm

Re: creating slideshow of images on RaspberryPi3 with Python3

Thu Apr 26, 2018 2:30 pm

i'm looking for a slideshow that can view images and a webpage like live weather can somebody help me

angus1024
Posts: 10
Joined: Thu May 10, 2018 6:10 am

Re: creating slideshow of images on RaspberryPi3 with Python3

Thu Jun 07, 2018 7:15 am

I dont know about the webpage but generating a slideshow of .jpg (at /home/pi/share/pics ) from within python is :

Code: Select all

import os
s='sudo feh -Z-z-F-D 4 --hide-pointer -auto-rotate /home/pi/share/pics'
os.system(s)
 
which would change the picture every 4 secs

User avatar
DougieLawson
Posts: 36331
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: creating slideshow of images on RaspberryPi3 with Python3

Thu Jun 07, 2018 11:25 am

There's a ready built solution: https://pipresents.wordpress.com
That includes a bunch of bells & whistles as it's designed to make presentations in museums.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Galbi3000
Posts: 2
Joined: Thu Jan 21, 2016 7:03 pm

Re: creating slideshow of images on RaspberryPi3 with Python3

Sun Oct 21, 2018 3:45 pm

angus1024 wrote:
Thu Jun 07, 2018 7:15 am
I dont know about the webpage but generating a slideshow of .jpg (at /home/pi/share/pics ) from within python is :

Code: Select all

import os
s='sudo feh -Z-z-F-D 4 --hide-pointer -auto-rotate /home/pi/share/pics'
os.system(s)
 
which would change the picture every 4 secs
This is not exactly using Python to do the slideshow, it's using Python to start another program! Also, the program you are starting, feh, is not installed by default in Raspbian which you do not even point out, not helpful at all :P

Return to “Python”