Created
May 8, 2020 12:52
-
-
Save kilomeow/682c3c593fdda3319c9b94be9c710094 to your computer and use it in GitHub Desktop.
script for resizing images to the appropriate telegram stickers format
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
#!/usr/bin/python | |
from PIL import Image | |
import os, sys | |
basewidth = 512 | |
def resize(path): | |
dirs = os.listdir(path) | |
for fn in dirs: | |
fp = os.path.join(path, fn) | |
n, e = os.path.splitext(fn) | |
if os.path.isfile(fp): | |
try: | |
img = Image.open(fp) | |
except: | |
print('skip', fn) | |
else: | |
wpercent = (basewidth/float(img.size[0])) | |
hsize = int(img.size[1]*wpercent) | |
img = img.resize((basewidth,hsize), Image.ANTIALIAS) | |
img.save(f'{n}.png', 'PNG') | |
if __name__ == '__main__': | |
resize(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment