Refine rendering and packing logic
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
from .assets import load_json, load_rgb
|
||||
from .settings import BOARD_DECK, DECKS_DIR, BuildConfig
|
||||
|
||||
ORIGINAL_BOARD_MM = (88.9, 139.7)
|
||||
@@ -45,17 +44,6 @@ def board_target_mm_for_mode(
|
||||
|
||||
return BOARD_SIZE_OPTIONS_MM.get(board_mode, ORIGINAL_BOARD_MM)
|
||||
|
||||
|
||||
def board_aspect_ratio(board_path: Path) -> float:
|
||||
deck_json = board_path.parent / "deck.json"
|
||||
if deck_json.exists():
|
||||
meta = load_json(deck_json)
|
||||
if meta.get("cardWidth") and meta.get("cardHeight"):
|
||||
return float(meta["cardWidth"]) / float(meta["cardHeight"])
|
||||
with load_rgb(board_path) as img:
|
||||
return img.width / img.height
|
||||
|
||||
|
||||
def board_target_mm(board_path: Path, config: BuildConfig) -> tuple[float, float]:
|
||||
return board_target_mm_for_mode(board_path, config.board_mode, config.board_custom_mm)
|
||||
|
||||
@@ -78,15 +66,3 @@ def board_size_fits_paper(
|
||||
if not (fits_upright or fits_rotated):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def board_mode_fits_paper(board_mode: str, paper_mm: tuple[float, float], margin_mm: float) -> bool:
|
||||
return board_size_fits_paper(board_mode, None, paper_mm, margin_mm)
|
||||
|
||||
|
||||
def crop_board_bleed(img):
|
||||
target_w = round(img.width * (3.5 / 3.75))
|
||||
target_h = round(img.height * (5.5 / 5.75))
|
||||
left = max(0, (img.width - target_w) // 2)
|
||||
top = max(0, (img.height - target_h) // 2)
|
||||
return img.crop((left, top, left + target_w, top + target_h))
|
||||
|
||||
Reference in New Issue
Block a user