Created
February 24, 2015 20:23
-
-
Save etataurov/e053c0709c1bcd0dc078 to your computer and use it in GitHub Desktop.
This file contains 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 | |
filename = sys.argv[1] | |
my_new_image = Image.new('RGB', (510, 311), (255,255,255,0)) | |
old_image = Image.open(filename) | |
old_size = old_image.size | |
aspect = old_size[0] / float(old_size[1]) | |
new_width = int(aspect*311) | |
paste = (510 - new_width)/2 | |
pasted = old_image.resize((new_width, 311), Image.LANCZOS) | |
my_new_image.paste(pasted, box=(paste, 0), mask=pasted) | |
my_new_image.save(filename.rsplit('.', 1)[-2]+'_result.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment