Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Last active September 7, 2016 21:41
Show Gist options
  • Save shinshin86/a6df94e403857d1c0a77ae589d76735c to your computer and use it in GitHub Desktop.
Save shinshin86/a6df94e403857d1c0a77ae589d76735c to your computer and use it in GitHub Desktop.
Image resize to half.
# -*-coding: utf-8-*-
import glob
import os
from PIL import Image;
# Get all of the image files that exist under the "work" directory.
file_list = [r.split('/')[-1] for r in glob.glob('./work/*')]
for f in file_list:
file_extension = os.path.splitext(f)
target_file_extension = [".jpeg", ".jpe", ".jpg", ".JPEG",".png",".PNG",".gif",".GIF",".bmp",".BMP"]
if file_extension[1] in target_file_extension:
file = "work/" + f
target_image = Image.open(file)
x_size = int(target_image.size[0] / 2)
y_size = int(target_image.size[1] / 2)
target_image2= target_image.resize((x_size,y_size))
resize_name = 'result/' + f
# Put a resize image to "result" directory
target_image2.save(resize_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment