-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgifs.py
32 lines (26 loc) · 968 Bytes
/
gifs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from PIL import Image
import imageio
import os
import time
def cargar_imagenes():
folder_path = './Animales generados/Vacas' # Ruta al directorio que contiene las imágenes
imagenes = []
# Recorrer el directorio y cargar las imágenes
for filename in os.listdir(folder_path):
img_path = os.path.join(folder_path, filename)
if os.path.isfile(img_path):
img = Image.open(img_path)
img = img.resize((128, 128)) # Ajusta el tamaño si es necesario
imagenes.append(img)
return imagenes
# Obtener las imágenes
imagenes = cargar_imagenes()
# Crear el GIF
with imageio.get_writer('output.gif', mode='I', duration=2) as writer:
for img in imagenes:
img.save('temp.gif')
image = imageio.imread('temp.gif')
writer.append_data(image)
time.sleep(0.5) # Esperar 0.5 segundos antes de pasar a la siguiente imagen
# Eliminar el archivo temporal
os.remove('temp.gif')