#!/usr/bin/env python3 from pathlib import Path from subprocess import run from typing import 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()