Skip to content

Instantly share code, notes, and snippets.

@JoeThunyathep
Last active April 10, 2024 20:46
Show Gist options
  • Save JoeThunyathep/e8f843e26ec822ec9cec58c9ba3e9431 to your computer and use it in GitHub Desktop.
Save JoeThunyathep/e8f843e26ec822ec9cec58c9ba3e9431 to your computer and use it in GitHub Desktop.
Resize images in a folder using Pillow
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