Last active
February 24, 2022 21:27
-
-
Save lucascompython/b0648a30386cc049e3cd3b5fbbf141c4 to your computer and use it in GitHub Desktop.
This is a very simple image resizer that keeps the aspect ratio.
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
import os, sys | |
from PIL import Image | |
def rezise(dir, size: tuple = (768, 512)) -> None: | |
for infile in os.listdir(dir): | |
outfile = os.path.splitext(infile)[0] + "_resized.thumbnail" | |
if infile != outfile: | |
try: | |
with Image.open(os.path.join(dir, infile)) as im: | |
cp = im.copy() | |
cp.thumbnail(size, Image.ANTIALIAS) | |
cp.save(os.path.join(dir, outfile), "JPEG") | |
print("Resized: " + infile) | |
except IOError: | |
print("Cannot resize " + infile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment