diff --git a/render.py b/render.py new file mode 100755 index 0000000..b7cfeac --- /dev/null +++ b/render.py @@ -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()