Created
January 11, 2023 10:44
-
-
Save jensadev/e23ef05b7cfb72dec2638c08ddf8544e to your computer and use it in GitHub Desktop.
Thumbnailer i python
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 | |
size = (320, 240) | |
# https://pillow.readthedocs.io/en/stable/handbook/tutorial.html | |
# kör programmet med python3 thumb.py *.jpg | |
for infile in sys.argv[1:]: | |
outfile = os.path.splitext(infile)[0] + "_thumbnail.jpg" | |
if infile != outfile: | |
try: | |
with Image.open(infile) as im: | |
im.thumbnail(size) | |
im.save(outfile, "JPEG") | |
except OSError: | |
print("cannot create thumbnail for", infile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment