Last active
July 11, 2021 08:23
-
-
Save jeremypruitt/0e88d95e90019117d7059c0c42b4da1b to your computer and use it in GitHub Desktop.
Generates an animated gif of a counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageSequence, ImageFont | |
import io | |
import click | |
FIRST_NUMBER = click.prompt('Enter the low number of the range', default=10330, type=int) | |
LAST_NUMBER = click.prompt('Enter the high number of the range', default=10346, type=int) | |
FRAME_DURATION = click.prompt('How long to hold on each number', default=100, type=int) | |
ANIMATED_GIF_FILENAME = click.prompt('Enter the name of the animated gif to generate', default="incrementing-counter.gif", type=str) | |
TEXT_COLOR = (255,255,255) | |
TEXT_SIZE = (5,-2) | |
TEXT_BG_COLOR = (0,0,0) | |
TEXT_BG_SIZE = (115,40) | |
# Download: https://github.com/blaisck/sfwin/blob/master/SFPro/TrueType/SFProDisplay-Regular.ttf | |
fnt = ImageFont.truetype("SFProDisplay-Regular.ttf", 36) | |
frames = [] | |
for count in list(range(FIRST_NUMBER, LAST_NUMBER)): | |
new_img = Image.new('RGB', TEXT_BG_SIZE, TEXT_BG_COLOR) | |
draw = ImageDraw.Draw(new_img) | |
draw.text(TEXT_SIZE, str(count), font = fnt, fill=TEXT_COLOR) | |
frames.append(new_img) | |
frames[0].save(ANIMATED_GIF_FILENAME, format='GIF', | |
append_images=frames[1:], save_all=True, duration=FRAME_DURATION, loop=0) | |
print(f'Generated animated gif at ./{ANIMATED_GIF_FILENAME}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3 alice2.py | |
Enter the low number of the range [10330]: | |
Enter the high number of the range [10346]: 10999 | |
How long to hold on each number [100]: 50 | |
Enter the name of the animated gif to generate [incrementing-counter.gif]: | |
Generated animated gif at ./incrementing-counter.gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment