Skip to content

Instantly share code, notes, and snippets.

@sinofp

sinofp/crtgif.py Secret

Created May 27, 2021
Embed
What would you like to do?
# -*- coding: utf-8 -*-
from PIL import Image
import sys
ROW = 40
FPS = 60
if len(sys.argv) < 1:
print("Please specify picture name.")
im = Image.open(sys.argv[1])
width, height = im.size
frames = []
box = (0, 0, width, ROW)
for i in range(0, height, ROW):
region = im.crop(box)
blank = Image.new(im.mode, im.size)
blank.paste(region, box)
frames.append(blank)
box = (0, box[3], width, box[3] + ROW if box[3] + ROW < height else height)
frames[0].save(
im.filename[: im.filename.find(".", 1)] + "_crt.gif",
"GIF",
# https://www.quora.com/What-is-the-optimal-frame-rate-for-an-animated-GIFS
duration=round(1 / FPS * 100) * 10,
save_all=True,
append_images=frames[1:],
loop=0,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment