Skip to content

Instantly share code, notes, and snippets.

@AVJdataminer
Last active May 14, 2020 01:49
Show Gist options
  • Save AVJdataminer/600b6d2baa35d3a642f9fa3603048f34 to your computer and use it in GitHub Desktop.
Save AVJdataminer/600b6d2baa35d3a642f9fa3603048f34 to your computer and use it in GitHub Desktop.
import PIL
from PIL import Image
import os
import sys
path = "/path/to/file"
dirs = [file for file in os.listdir(path) if file.endswith('.png')]
#pixelsize = 500;
def resize_thumbnail():
for item in dirs:
if os.path.isfile(path+item):
image = Image.open(path+item)
file_path, extension = os.path.splitext(path+item)
image = Image.open(path+item)
image.thumbnail((500,500), Image.ANTIALIAS)
if image.mode in ("RGBA", "P"):
image = image.convert("RGB")
image.save(file_path + "_thumb.jpg" ,'JPEG', quality=90)
resize_thumbnail()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment