Allow for multi-page printing.

This commit is contained in:
2025-07-13 20:56:29 -05:00
parent a074455f92
commit 787f27ffa7

View File

@@ -315,26 +315,40 @@ def make_sheets (set_filename, scale_factor=(1, 1), card_size=None):
if os.path.isfile(set_filename):
set_filename = os.path.splitext(set_filename)[0]
sheet_size = (2550, 3300)
margins = (50, 50)
sheet = Image.new("RGBA", sheet_size)
(x, y) = margins
page_size = (2550, 3300)
margins = (50, 50)
(x, y) = margins
# collect card images to determine print sheet size
cards = []
pages = [cards]
for image_file in os.listdir(set_filename):
if not os.path.splitext(image_file)[1] in [".jpg", ".png"]:
continue
image = Image.open(os.path.join(set_filename, image_file))
size = (card_size[0], card_size[1]) if card_size else (image.width, image.height)
size = (card_size[0], card_size[1]) if card_size else (image.width, image.height)
image = image.resize((int(size[0] * scale_factor[0]), int(size[1] * scale_factor[1])))
cards.append((image, (x, y)))
sheet.paste(image, (x, y))
x = x + margins[0] + image.width
if x + image.width > sheet_size[0]:
if x + image.width > page_size[0]:
x = margins[0]
y = y + margins[1] + image.height
if y + image.width > page_size[1]:
x = margins[0]
y = margins[1]
cards = []
pages.append(cards)
sheet_size = (page_size[0], page_size[1] * len(pages))
sheet = Image.new("RGBA", sheet_size)
for i in range(0, len(pages)):
for card in pages[i]:
sheet.paste(card[0], (card[1][0], card[1][1] + (page_size[1] * i)))
sheet.save(f"{set_filename}.png")
def main():
@@ -354,6 +368,8 @@ def main():
frames = namespace.get("frames", {})
default_frame = namespace['default_frame']
sets = namespace['sets']
scale_factor = namespace.get("scale_factor", (1.1446, 1.1446))
for name, setdata in sets.items():
make_set(setdata, name, default_frame, frames)
make_sheets(name, scale_factor=scale_factor)