83 lines
1.9 KiB
Python
83 lines
1.9 KiB
Python
from PIL import Image, ImageDraw, ImageFont
|
|
import os
|
|
|
|
# ==========================
|
|
# Settings
|
|
# ==========================
|
|
|
|
START_NUMBER = 3398 # First number
|
|
NUM_PAGES = 9 # Number of pages to generate
|
|
|
|
ROWS = 8
|
|
COLS = 3
|
|
|
|
# A4 at 300 DPI
|
|
PAGE_WIDTH = 2480
|
|
PAGE_HEIGHT = 3508
|
|
|
|
MARGIN_X = 0
|
|
MARGIN_Y = 0
|
|
|
|
OUTPUT_FOLDER = "output"
|
|
|
|
# Font
|
|
FONT_SIZE = 80
|
|
|
|
# Optional: use your own TTF font
|
|
FONT_PATH = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
|
|
# FONT_PATH = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
|
|
|
|
# ==========================
|
|
|
|
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
|
|
|
|
try:
|
|
font = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
|
except OSError:
|
|
print("Font not found. Using default font.")
|
|
font = ImageFont.load_default()
|
|
|
|
usable_width = PAGE_WIDTH - 2 * MARGIN_X
|
|
usable_height = PAGE_HEIGHT - 2 * MARGIN_Y
|
|
|
|
cell_width = usable_width / COLS
|
|
cell_height = usable_height / ROWS
|
|
|
|
current = START_NUMBER
|
|
current_start = START_NUMBER
|
|
current_end = START_NUMBER
|
|
|
|
for page in range(NUM_PAGES):
|
|
|
|
current_start = current -1
|
|
image = Image.new("RGB", (PAGE_WIDTH, PAGE_HEIGHT), "white")
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
for row in range(ROWS):
|
|
for col in range(COLS):
|
|
|
|
number = f"{current:04d}"
|
|
|
|
left = MARGIN_X + col * cell_width
|
|
top = MARGIN_Y + row * cell_height
|
|
|
|
bbox = draw.textbbox((0, 0), number, font=font)
|
|
text_width = bbox[2] - bbox[0]
|
|
text_height = bbox[3] - bbox[1]
|
|
|
|
x = left + (cell_width - text_width) / 2
|
|
y = top + (cell_height - text_height) / 2
|
|
|
|
draw.text((x, y), number, fill="black", font=font)
|
|
|
|
current += 1
|
|
current_end = current -2
|
|
filename = os.path.join(
|
|
OUTPUT_FOLDER,
|
|
#f"numbers_page_{page + 1:03d}.png"
|
|
f"{current_start+ 1:04d}-{current_end+1:04d}.png"
|
|
)
|
|
image.save(filename)
|
|
|
|
print(f"Generated {NUM_PAGES} page(s).")
|
|
print(f"Last number: {current - 1:04d}") |