You've already forked etude_lego_jurassic_world
Filtre les collages globaux sur les personnages multi-variations
This commit is contained in:
@@ -121,3 +121,41 @@ def build_character_collages(
|
||||
)
|
||||
)
|
||||
return generated
|
||||
|
||||
|
||||
def filter_characters_with_variations(
|
||||
grouped_entries: Dict[str, Sequence[dict]],
|
||||
min_variations: int = 2,
|
||||
) -> Dict[str, Sequence[dict]]:
|
||||
"""Conserve uniquement les personnages ayant un nombre minimal de variations (fig_num distincts)."""
|
||||
filtered: Dict[str, Sequence[dict]] = {}
|
||||
for character, entries in grouped_entries.items():
|
||||
variations = {entry["fig_num"] for entry in entries}
|
||||
if len(variations) >= min_variations:
|
||||
filtered[character] = entries
|
||||
return filtered
|
||||
|
||||
|
||||
def stack_collages(
|
||||
source_dir: Path,
|
||||
destination_path: Path,
|
||||
spacing: int = 18,
|
||||
allowed_stems: Set[str] | None = None,
|
||||
) -> None:
|
||||
"""Superpose verticalement toutes les frises présentes dans un dossier."""
|
||||
images: List[Image.Image] = []
|
||||
for path in sorted(source_dir.glob("*.png")):
|
||||
if allowed_stems is not None and path.stem not in allowed_stems:
|
||||
continue
|
||||
images.append(Image.open(path).convert("RGB"))
|
||||
if not images:
|
||||
return
|
||||
max_width = max(image.width for image in images)
|
||||
total_height = sum(image.height for image in images) + spacing * (len(images) - 1)
|
||||
canvas = Image.new("RGB", (max_width, total_height), (255, 255, 255))
|
||||
y = 0
|
||||
for image in images:
|
||||
canvas.paste(image, (0, y))
|
||||
y += image.height + spacing
|
||||
ensure_parent_dir(destination_path)
|
||||
canvas.save(destination_path)
|
||||
|
||||
Reference in New Issue
Block a user