Foo.
This commit is contained in:
parent
38de96de6d
commit
989a175fa5
5 changed files with 173 additions and 2 deletions
17
misc.py
Normal file
17
misc.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
from PIL import Image
|
||||
|
||||
def resize_image(img, size, blackbg=True):
|
||||
tw, th = size
|
||||
w, h = img.size
|
||||
a, b = w/tw, h/th
|
||||
f = 1/max(a, b)
|
||||
pos = int((tw-w*f)/2), int((th-h*f)/2)
|
||||
buf = Image.new('RGBA', (tw, th))
|
||||
buf.paste(img.resize((int(w*f), int(h*f))).convert('RGBA'), pos)
|
||||
if blackbg:
|
||||
buf2 = Image.new('RGBA', (tw, th), (0, 0, 0, 255))
|
||||
return Image.alpha_composite(buf2, buf)
|
||||
else:
|
||||
return buf
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue