Last active
August 6, 2019 19:23
-
-
Save jsalbert/ba469279e123276ea16ef55bfd5df1d3 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
from PIL import Image | |
def center_crop(image): | |
# crop to ratio, center | |
w, h = image.size | |
w_center = w/2 | |
h_center = h/2 | |
if w > h: | |
image = image.crop((w_center - h/2, 0, w_center + h/2, h)) | |
else: | |
image = image.crop((0, h_center - w/2, w, h_center + w/2)) | |
return image | |
image = center_crop(Image.open(file_source)) | |
image.save(file_destination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment