foo2 = foo.copy() draw = ImageDraw.Draw(foo2) for i in range(width): draw.rectangle([i, i, foo2.size[0]-i-1, foo2.size[1]-i-1], outline = color)
foo2 will have a width pixel border color .
If you need different colored borders on each side, you can replace .rectangle with repeated calls to .line .
If you want the frame to not cover any part of the existing image, use foo.copy() instead.
foo2 = Image.new(foo.mode, (foo.size[0] + 2*width, foo.size[1] + 2*width)) foo2.paste(foo, (width, width))
source share