Skip to content

Instantly share code, notes, and snippets.

@flyte
Last active December 28, 2015 20:29
Show Gist options
  • Save flyte/7557719 to your computer and use it in GitHub Desktop.
Save flyte/7557719 to your computer and use it in GitHub Desktop.
Split img down the middle vertically.
from PIL import Image
def split_img(img_path):
"""
Splits an image vertically down the middle and returns a tuple
containing (left_half, right_half) Pillow Image objects.
"""
img = Image.open(img_path)
width, height = img.size
half_width = int(width/2)
left_half = img.crop((0, 0, half_width, height))
right_half = img.crop((half_width, 0, width, height))
return (left_half, right_half)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment