Last active
August 9, 2016 14:40
-
-
Save squamous/bee9d1d50b4d51311c6af0abe58bba59 to your computer and use it in GitHub Desktop.
Resize a set of images by a given percentage
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
#!/usr/bin/env python | |
# | |
# Resize a set of images by a given percentage. | |
import sys, os | |
from PIL import Image | |
if __name__ == '__main__': | |
if len(sys.argv) > 2: | |
percentage = int(sys.argv[1]) / float(100) | |
print 'Resizing each image by %s%%' % (percentage * 100) | |
imgs = sys.argv[2:] | |
for fname in imgs: | |
img = Image.open(fname) | |
w, h = img.size | |
img = img.resize( | |
(int(w * percentage), int(h * percentage)), | |
Image.BILINEAR | |
) | |
img.save("resize_%s" % fname) | |
else: | |
print '%s <percentage> [file ...]' % os.path.basename(sys.argv[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment