Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
UncertainProd
GitHub Repository: UncertainProd/FnF-Spritesheet-and-XML-Maker
Path: blob/master/src/engine/imgutils.py
254 views
1
from PIL import Image
2
3
DEFAULT_PADDING = 1
4
5
def pad_img(img, clip=False, top=DEFAULT_PADDING, right=DEFAULT_PADDING, bottom=DEFAULT_PADDING, left=DEFAULT_PADDING):
6
if clip:
7
img = img.crop(img.getbbox())
8
9
width, height = img.size
10
new_width = width + right + left
11
new_height = height + top + bottom
12
result = Image.new('RGBA', (new_width, new_height), (0, 0, 0, 0))
13
result.paste(img, (left, top))
14
return result
15
16
def clean_up(*args):
17
for img in args:
18
img.close()
19