-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_combiner.py
52 lines (38 loc) · 1.4 KB
/
image_combiner.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
import os
import math
import PIL
import text_parser
from PIL import Image
from scryfall import imagesDirectory
sheetsDirectory = 'Sheets/'
offset = 68
if not os.path.exists(sheetsDirectory):
os.makedirs(sheetsDirectory)
def combine_images(cardList):
cardImages = []
#create list of card images
for cardTuple in cardList:
path = imagesDirectory + '/' + cardTuple[1] + '.png'
#skip over cards that have no images
if not os.path.exists(path):
continue
cardImage = Image.open(path)
cardImage = cardImage.resize((745, 1040), PIL.Image.Resampling.BICUBIC)
for i in range(0 , cardTuple[0], 1):
cardImages.append(cardImage)
#split into sheets of 9
sheetCount = math.ceil(len(cardImages)/9)
print(str(sheetCount) + ' sheet(s) will be produced.')
for m in range(0, sheetCount, 1):
canvas = Image.new(mode='RGB', size=(2550, 3300), color=(255,255,255))
for t in range(offset,2235+offset,765):
for g in range(offset,3120+offset,1060):
#paste the image at location i,j:
if(len(cardImages) != 0):
canvas.paste(cardImages.pop(), (t,g))
#canvas.show()
canvas.save(sheetsDirectory + 'sheet' + str(m+1) + '.png', resolution=300)
def clean_sheets():
for file in os.scandir(sheetsDirectory):
os.remove(file)