Skip to content

Instantly share code, notes, and snippets.

@arth2o
Created October 18, 2022 09:05
Show Gist options
  • Save arth2o/e79dca65372e825876c4e09db2540d67 to your computer and use it in GitHub Desktop.
Save arth2o/e79dca65372e825876c4e09db2540d67 to your computer and use it in GitHub Desktop.
Resize .jpg in a folder keep aspect ratio. New image name will be extend with _t tag.
#!/usr/bin/python
# install
# pip install super-image
from PIL import Image
import os, sys, glob
path = "./"
dirs = os.listdir( path )
def resize():
path = "./"
dirs = glob.glob(path+'*.jpg')
for item in dirs:
im = Image.open(path+item)
f, e = os.path.splitext(path+item)
# keep image aspect ratio
im.thumbnail((2000,2000))
print(f);
im.save(f + '_t.jpg', 'JPEG', quality=72)
resize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment