Funny I was looking at some like this as well. I basically created the same thing but taking the jpg and creating a GIF so I can display in card in HA. (converts to png and then to gif, as I was having an issue with the jpeg file). It runs every 30 minutes currently. Be kind it’s my first go at this.
I used Appdaemon to do so. Below is the setup if you are interested. Below is the conifg for Appdaemon.
{
“disable_auto_token”: false,
“system_packages”: [
“libcurl”,
“zlib-dev”,
“libjpeg”,
“libwebp”,
“libjpeg-turbo”,
“tk”,
“tiff-dev”,
“openjpeg”,
“python3-dev”,
“curl-dev”,
“gcc”,
“g++”
],
“python_packages”: [
“imageio”,
“Image”
]
}
And then updated the apps.yaml file and created a save_gif.py file.
apps.yaml
save_gif:
module: save_gif
class: Savegif
save_gif.py
import appdaemon.plugins.hass.hassapi as hass
import os
import imageio
import shutil
import datetime
import glob
import time
from stat import S_ISREG, ST_CTIME, ST_MODE
from PIL import Imageclass Savegif(hass.Hass):
def initialize(self):
self.run_daily_c()
def run_daily_c(self):
# Waits for 30 minutes time.sleep(1800) self.png_dir = '/config/www/deepstack_person_images/' self.png_dir1 = '/config/www/png/' self.images = [] # Deletes old files from copied folder for file in os.scandir(self.png_dir1): if file.name.endswith(".PNG"): os.unlink(file) # Sorts by file name for self.file_name in sorted(os.listdir(self.png_dir)): # Copies jpg to new folder and converts to png if not self.file_name.startswith("."): self.file_path = os.path.join(self.png_dir, self.file_name) self.filename1 = os.path.splitext(self.file_name)[0] self.file_path1 = os.path.join(self.png_dir1, self.filename1 + '.PNG') print (self.file_path) print (self.file_path1) self.im = Image.open(self.file_path) self.im.save(self.file_path1, "PNG") self.images.append(imageio.imread(self.file_path1,'.PNG')) # Creates gif file imageio.mimsave('/config/www/output.gif',self.images,fps=.6) # Deletes png files again for file in os.scandir(self.png_dir1): if file.name.endswith(".PNG"): os.unlink(file) while True: self.initialize()