Skip to content

Instantly share code, notes, and snippets.

@greencoder
Created May 18, 2021 19:55
Show Gist options
  • Save greencoder/efe8ebbe8ecee62471a216a91742005d to your computer and use it in GitHub Desktop.
Save greencoder/efe8ebbe8ecee62471a216a91742005d to your computer and use it in GitHub Desktop.
Create "pulsing" animated gifs with Pillow
from PIL import Image
colors = {
'prearrival': (165, 226, 250, 255),
'arrived': (253, 245, 210, 255),
'waiting': (170, 255, 190, 255),
'waiting_long': (255, 160, 159, 255),
'unreviewed': (255, 160, 159, 255),
}
for name, color_values in colors.items():
images = []
for step in range(0,11):
opacity = int(step * 0.1 * 255)
img_number1 = str(step).zfill(2)
img_number2 = 21 - step
color = (color_values[0], color_values[1], color_values[2], opacity)
base_image = Image.new('RGBA', (100,100), color='white')
color_image = Image.new('RGBA', (100,100), color=color)
new_image = Image.alpha_composite(base_image, color_image)
images.append(new_image)
all_images = images + images[::-1]
images[0].save(f'output/{name}.gif', save_all=True, append_images=all_images, duration=10, loop=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment