-
-
Save gchiappe/2b43c1e948169084dff3e4fded14f8e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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