Skip to content

Instantly share code, notes, and snippets.

@sinofp

sinofp/crtgif.py Secret

Created May 27, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinofp/80a6d0eb773827546241f5002eb4c217 to your computer and use it in GitHub Desktop.
Save sinofp/80a6d0eb773827546241f5002eb4c217 to your computer and use it in GitHub Desktop.
# -*- 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