Skip to content

Instantly share code, notes, and snippets.

@gchiappe
Forked from fabeat/scale.py
Last active July 11, 2016 15:01
Show Gist options
  • Save gchiappe/2b43c1e948169084dff3e4fded14f8e6 to your computer and use it in GitHub Desktop.
Save gchiappe/2b43c1e948169084dff3e4fded14f8e6 to your computer and use it in GitHub Desktop.
from PIL import Image
def add_whitespaces(image, max_size):
"""
Adds white spaces until the image reaches the desired max_size.
Forked from: https://gist.github.com/fabeat/6621507
:param image: Image
:param max_size: [ W , H ]
:return: Image
"""
offset = (((max_size[0] - image.size[0]) / 2), ((max_size[1] - image.size[1]) / 2))
back = Image.new("RGB", max_size, "white")
back.paste(image, offset)
return back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment