Skip to content

Instantly share code, notes, and snippets.

@syanyong
Created April 9, 2022 08:59
Show Gist options
  • Save syanyong/c2aae15af4249a81b8775bbe575d3418 to your computer and use it in GitHub Desktop.
Save syanyong/c2aae15af4249a81b8775bbe575d3418 to your computer and use it in GitHub Desktop.
### Usage: python resize.py <directory of image>
### Example: python resize.py ~/Desktop/MyImages/
import os, sys
from PIL import Image
import glob
# Resize size (will maintain the aspect ratio)
size = 224, 224
i = 0
for dirname in sys.argv[1:]:
files = glob.glob(str(dirname)+"*.jpeg")
for infile in files:
new_name = os.path.dirname(infile)+"/%d.jpeg" % i
print(infile, new_name)
os.rename(infile, new_name)
i = i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment