Created
April 6, 2017 14:10
-
-
Save hapo31/065b72125f041ac69a9ae12a9f5dc0f1 to your computer and use it in GitHub Desktop.
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 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