Skip to content

Instantly share code, notes, and snippets.

@squamous
Last active August 9, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squamous/bee9d1d50b4d51311c6af0abe58bba59 to your computer and use it in GitHub Desktop.
Save squamous/bee9d1d50b4d51311c6af0abe58bba59 to your computer and use it in GitHub Desktop.
Resize a set of images by a given percentage
#!/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