Created
October 5, 2016 17:44
-
-
Save asciimo/267e88e34996466603194340475696be to your computer and use it in GitHub Desktop.
Little utility to resize globbed images
This file contains hidden or 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
Pillow==3.4.1 | |
python-resize-image==1.1.3 |
This file contains hidden or 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 | |
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