Last active
April 10, 2024 20:46
-
-
Save JoeThunyathep/e8f843e26ec822ec9cec58c9ba3e9431 to your computer and use it in GitHub Desktop.
Resize images in a folder using Pillow
This file contains hidden or 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
from PIL import Image | |
import pathlib | |
maxsize = (512, 512) | |
for input_img_path in pathlib.Path("input").iterdir(): | |
output_img_path = str(input_img_path).replace("input","output") | |
with Image.open(input_img_path) as im: | |
im.thumbnail(maxsize) | |
im.save(output_img_path, "JPEG", dpi=(300,300)) | |
print(f"processing file {input_img_path} done...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment