Skip to content

Instantly share code, notes, and snippets.

@hapo31
Created April 6, 2017 14:10
Show Gist options
  • Save hapo31/065b72125f041ac69a9ae12a9f5dc0f1 to your computer and use it in GitHub Desktop.
Save hapo31/065b72125f041ac69a9ae12a9f5dc0f1 to your computer and use it in GitHub Desktop.
import sys
from PIL import Image
def main():
filename = ""
if len(sys.argv) <= 1:
print("input filename:")
filename = input()
else:
filename = sys.argv[1]
img = Image.open(filename)
size = img.size
greater_side = size[0] if size[0] > size[1] else size[1]
ratio = 128.0 / float(greater_side)
img = img.resize((int(size[0] * ratio), int(size[1] * ratio)))
fname = filename.split(".")
img.save("%s_resized.%s" % (".".join(fname[0:-1]), fname[-1]))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment