Skip to content

Instantly share code, notes, and snippets.

@namieluss
Created March 16, 2020 05:36
Show Gist options
  • Save namieluss/a440061734075d929f0c6b9f6bd919c7 to your computer and use it in GitHub Desktop.
Save namieluss/a440061734075d929f0c6b9f6bd919c7 to your computer and use it in GitHub Desktop.
Add Borders to Images using Python Pillow
from PIL import Image, ImageOps
# open image
img = Image.open("test_image.jpg")
# border color
color = "green"
# top, right, bottom, left
border = (20, 10, 20, 10)
new_img = ImageOps.expand(img, border=border, fill=color)
# save new image
new_img.save("test_image_result.jpg")
# show new bordered image in preview
new_img.show()
@ehmatthes
Copy link

@blissdismissed Are you running the original code, or the code I shared recently? Can you share your full traceback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment