-
Notifications
You must be signed in to change notification settings - Fork 5
/
image.py
36 lines (30 loc) · 1.04 KB
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from PIL import Image
from background import *
from config import *
from patterns import *
import random
import os
def addImage(image, source):
new = Image.open(source).convert("RGBA")
image.paste(new, (0, 0, width, height), new)
return image
def createExample():
card = createBackground()
for i in patterns:
files = os.listdir('resource/'+i['name'])
file = random.choice(files)
card = addImage(card,'resource/'+i['name']+'/'+file)
card.save("result/example.png", format="png")
card.show()
def createImage(list_patterns):
card = createBackground()
for i in list_patterns:
card = addImage(card,'resource/'+i['directory']+'/'+i['file'])
if has_resize:
card = resizeImage(card)
card.save("result/new.png", format="png")
def resizeImage(image):
image = image.resize((int(width*resize_width), int(height*resize_height),), Image.NEAREST)
return image
def saveImage(canva, name, local = "result/"):
canva.save(local+name+"-"+sufix_to_reference_obj+".png", format="png")