1
Fork 0

Add the render script.

This commit is contained in:
Bauke 2022-10-11 20:08:33 +02:00
parent 089f09864b
commit 692e1eafc4
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 44 additions and 0 deletions

44
render.py Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
from pathlib import Path
from subprocess import run
from typing import Any, List, Optional
def main() -> None:
resolutions = [64, 128, 256, 512, 1024, 2048]
for svg in Path("public/").glob("**/*.svg"):
if "square" in str(svg):
for resolution in resolutions:
convert_to_image(
source=svg,
destination=svg.with_name(f"{svg.stem}-{resolution}.png"),
width=resolution,
height=resolution,
)
else:
convert_to_image(source=svg, destination=svg.with_suffix(".png"))
def convert_to_image(
source: Path,
destination: Path,
width: Optional[int] = None,
height: Optional[int] = None,
) -> None:
inkscape_args: List[str] = ["inkscape", str(source), "-o", str(destination)]
if width is not None and height is not None:
inkscape_args.extend(["-w", str(width), "-h", str(height)])
run(args=inkscape_args)
mat2_image(destination)
def mat2_image(image: Path) -> None:
run(args=["mat2", "--inplace", image])
if __name__ == "__main__":
main()