Skip to content

Instantly share code, notes, and snippets.

@kilomeow
Created May 8, 2020 12:52
Show Gist options
  • Save kilomeow/682c3c593fdda3319c9b94be9c710094 to your computer and use it in GitHub Desktop.
Save kilomeow/682c3c593fdda3319c9b94be9c710094 to your computer and use it in GitHub Desktop.
script for resizing images to the appropriate telegram stickers format
#!/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