Spaces:
Running
on
Zero
Running
on
Zero
#!/usr/bin/env python3 | |
# reads in a rectangular image, cuts it in half length-wise, and attaches the right half to the bottom, reversed | |
import sys | |
from PIL import Image | |
def rect_to_square(img): | |
# get width and height of img | |
w, h = img.size | |
new_img = Image.new(img.mode, (w//2, h*2)) | |
new_img.paste(img.crop((0, 0, w, h)), (0, 0)) | |
new_img.paste(img.crop((0, 0, w, h)).transpose(Image.FLIP_LEFT_RIGHT), (0, h)) | |
return new_img | |
if __name__ == '__main__': | |
img_filename = sys.argv[1] | |
in_img = Image.open(img_filename) | |
print("Input image dimenions: ", in_img.size) | |
out_img = rect_to_square(in_img) | |
print("Output image dimenions: ", out_img.size) | |
out_filename = img_filename.replace('.png', '_square.png') | |
print("Saving to ", out_filename) | |
out_img.save(out_filename) | |