Crear un GIF con Python

In [15]:
import matplotlib.image as image
import numpy as np
from PIL import Image

img = np.zeros((120,120,3))
img1 = np.ones((120,120,3))

for i in range(img.shape[0]):
    for j in range(img.shape[1]):
        if i < j:
            img[i][j] = np.array([1,1,1])

for i in range(img1.shape[0]):
    for j in range(img1.shape[1]):
        if i < j:
            img1[i][j] = np.array([0,0,0])

im = Image.fromarray(np.uint8(img*255))
im1 = Image.fromarray(np.uint8(img1*255))

images = []
images.append(im)
images.append(im1)
images[0].save('img/nuevo-gif.gif',
               save_all=True,
               append_images=images[1:],
               optimize=False,
               duration=1000,
               loop=0)

No hay comentarios.:

Publicar un comentario