In [ ]:
 
In [ ]:
 
In [1]:
from PIL import Image
def add_margin(pil_img, top, right, bottom, left, color):
    width, height = pil_img.size
    new_width = width + right + left
    new_height = height + top + bottom
    result = Image.new(pil_img.mode, (new_width, new_height), color)
    result.paste(pil_img, (left, top))
    return result
In [2]:
im = Image.open("64746_system_monitor_icon.png")
In [4]:
for i in range(30):
    print(f"padding {i}")
    im_new = add_margin(im, i, 0, 0, 0, (255,255,255,0))
    display(im_new)
margin 0
margin 1
margin 2
margin 3
margin 4
margin 5
margin 6
margin 7
margin 8
margin 9
margin 10
margin 11
margin 12
margin 13
margin 14
margin 15
margin 16
margin 17
margin 18
margin 19
margin 20
margin 21
margin 22
margin 23
margin 24
margin 25
margin 26
margin 27
margin 28
margin 29
In [5]:
for i in range(30):
    print(f"paddingtopbototm {i}")
    im_new = add_margin(im, i, 0, i, 0, (255,255,255,0))
    display(im_new)
paddingtopbototm 0
paddingtopbototm 1
paddingtopbototm 2
paddingtopbototm 3
paddingtopbototm 4
paddingtopbototm 5
paddingtopbototm 6
paddingtopbototm 7
paddingtopbototm 8
paddingtopbototm 9
paddingtopbototm 10
paddingtopbototm 11
paddingtopbototm 12
paddingtopbototm 13
paddingtopbototm 14
paddingtopbototm 15
paddingtopbototm 16
paddingtopbototm 17
paddingtopbototm 18
paddingtopbototm 19
paddingtopbototm 20
paddingtopbototm 21
paddingtopbototm 22
paddingtopbototm 23
paddingtopbototm 24
paddingtopbototm 25
paddingtopbototm 26
paddingtopbototm 27
paddingtopbototm 28
paddingtopbototm 29
In [ ]: