Skip to content

Instantly share code, notes, and snippets.

@jensadev
Created January 11, 2023 10:44
Show Gist options
  • Save jensadev/e23ef05b7cfb72dec2638c08ddf8544e to your computer and use it in GitHub Desktop.
Save jensadev/e23ef05b7cfb72dec2638c08ddf8544e to your computer and use it in GitHub Desktop.
Thumbnailer i python
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