Animated GIF emoji support
This commit is contained in:
parent
6940a194d0
commit
67b88f84a9
1 changed files with 16 additions and 5 deletions
21
main.py
21
main.py
|
@ -9,7 +9,7 @@ import os # Filesystem
|
||||||
import mimetypes # Uploading files to homeserver
|
import mimetypes # Uploading files to homeserver
|
||||||
import html # HTML formatting
|
import html # HTML formatting
|
||||||
import requests # XKCD command
|
import requests # XKCD command
|
||||||
import subprocess # ping command (admin)
|
import subprocess # GIF Emojis, ping command (admin)
|
||||||
import random # roll command
|
import random # roll command
|
||||||
import datetime # Ratelimiting
|
import datetime # Ratelimiting
|
||||||
|
|
||||||
|
@ -87,13 +87,24 @@ def download_file(url, filename):
|
||||||
else:
|
else:
|
||||||
return False
|
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)
|
# Resize an image (squares only)
|
||||||
def resize_image(filename, size):
|
def resize_image(filename, size):
|
||||||
im = Image.open(filename)
|
original_filename = filename
|
||||||
im = im.resize((size,size))
|
|
||||||
# Remove .ext from the filename, insert _resized into it, and save it
|
|
||||||
filename = filename[:-4] + "_resized" + filename[-4:]
|
filename = filename[:-4] + "_resized" + filename[-4:]
|
||||||
im.save(filename)
|
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
|
return filename
|
||||||
|
|
||||||
# Mentions a user
|
# Mentions a user
|
||||||
|
|
Loading…
Reference in a new issue