Animated GIF emoji support

This commit is contained in:
deadcade 2022-06-12 13:26:17 +02:00
parent 6940a194d0
commit 67b88f84a9

19
main.py
View file

@ -9,7 +9,7 @@ import os # Filesystem
import mimetypes # Uploading files to homeserver
import html # HTML formatting
import requests # XKCD command
import subprocess # ping command (admin)
import subprocess # GIF Emojis, ping command (admin)
import random # roll command
import datetime # Ratelimiting
@ -87,12 +87,23 @@ def download_file(url, filename):
else:
return False
# GIF resizing
def thumbnails(frames, size):
for frame in frames:
thumbnail = frame.copy()
thumbnail.thumbnail((size, size), Image.ANTIALIAS)
yield thumbnail
# Resize an image (squares only)
def resize_image(filename, size):
im = Image.open(filename)
im = im.resize((size,size))
# Remove .ext from the filename, insert _resized into it, and save it
original_filename = filename
filename = filename[:-4] + "_resized" + filename[-4:]
if filename.endswith(".gif"):
# PIL does not properly hanle GIF images
subprocess.run(["gifsicle", "--resize", f"{str(size)}x{str(size)}", original_filename, "-o", filename], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
im = Image.open(original_filename)
im = im.resize((size,size))
im.save(filename)
return filename