How would you prefer viewing a family photo? As a bare picture or enclosed in a nice photo frame? In ImageOps
module, PIL provides a preliminary functionality to add a plain border around the image. Here is the syntax to achieve this:
img = ImageOps.expand(img, border, fill)
This code creates a border around the image. Internally, PIL just creates an image that has dimesions such that:
new_width = ( right_border_thickness + image_width + left_border_thickness ) new_height = ( top_border_thickness + image_height + bottom_border_thickness )
Then, the original image is pasted onto this new image to create the border effect. The border
argument in the preceding code suggests border thickness in pixels. It is uniform in this example and is set to 20 pixels for left, right, top, and bottom borders. The fill
argument specifies the border color. It can be a number in the range 0
to 255
indicating the pixel color, where 0
is for 'black' and 255
for 'white' border. Alternatively...