We value your privacy
This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content.
from PIL import Image import numpy as np # Set dimensions width = 400 height = 400 frames = 30 # Number of frames # Create list to store frames images = [] # Generate frames for i in range(frames): # Create new image img = Image.new("RGB", (width, height)) pixels = img.load() # Alternate between colors every frame if i % 2 == 0: color = (255, 0, 0) # Pure red else: color = (139, 0, 0) # Dark red # Fill image with color for x in range(width): for y in range(height): pixels[x, y] = color images.append(img) # Save as animated WebP images[0].save( "flickering_red.webp", save_all=True, append_images=images[1:], duration=50, # 50ms per frame - adjust this for faster/slower flickering loop=0, # Infinite loop quality=100, method=6, lossless=False, )