[Code Snippet] Adding borders to an image using Python

After a long time… I’m back!

Now, I going to show you how use python to add borders to an image.


import Image
import ImageOps

if __name__ == '__main__':
    image_name="terminator.jpg"
    new_image_name="terminator_with_border.jpg"
    image_file = Image.open(image_name)
    new_image_file = ImageOps.expand(image_file, border=10, fill='red')
    new_image_file.save(new_image_name)

Input image

Input image

Output image

Output image

That’s all folks!