Skip to content

Instantly share code, notes, and snippets.

@ShakyaMajumdar
Created March 6, 2021 12:00
Show Gist options
  • Save ShakyaMajumdar/2eeabfadd4536c7291f1b322f31313fa to your computer and use it in GitHub Desktop.
Save ShakyaMajumdar/2eeabfadd4536c7291f1b322f31313fa to your computer and use it in GitHub Desktop.
from PIL import Image, ImageSequence
LARGE = (55, 55)
SMALL = (48, 48)
pfp = Image.open('pfp.png')
pfps = [pfp.resize(LARGE), pfp.resize(SMALL)]
bonk_gif = Image.open('base.gif')
gif_dimensions = bonk_gif.size
white_bg = Image.new("RGBA", bonk_gif.size, "WHITE")
out_images = []
for i, frame in enumerate(ImageSequence.Iterator(bonk_gif)):
frame = frame.convert("RGBA")
bg = white_bg.copy()
bg.paste(frame, (0, 0), frame)
frame = bg.convert("RGBA")
if i == bonk_gif.n_frames - 1:
frame.paste(pfps[1], (0, gif_dimensions[1] - SMALL[1]))
else:
frame.paste(pfps[0], (0, gif_dimensions[1] - LARGE[1]))
out_images.append(frame)
out_images[0].save('out.gif', 'GIF', save_all=True, append_images=out_images[1:], loop=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment