Skip to content

Instantly share code, notes, and snippets.

@asciimo
Created October 5, 2016 17:44
Show Gist options
  • Save asciimo/267e88e34996466603194340475696be to your computer and use it in GitHub Desktop.
Save asciimo/267e88e34996466603194340475696be to your computer and use it in GitHub Desktop.
Little utility to resize globbed images
Pillow==3.4.1
python-resize-image==1.1.3
import os
from sys import argv
from PIL import Image
from resizeimage import resizeimage
def new_file_path(old_path):
path_parts = os.path.split(old_path)
filename_parts = path_parts[1].split('.')
new_filename = '%s_resized.%s' % (filename_parts[0], filename_parts[1])
return os.path.join(path_parts[0], new_filename)
for image_path in (argv[1:]):
with open(image_path, 'r+b') as f:
with Image.open(f) as image:
resized_image = resizeimage.resize_cover(image, [200, 200])
resized_image.save(new_file_path(image_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment