1
Fork 0

Switch the resolution to be an optional tuple.

This commit is contained in:
Bauke 2024-01-15 13:04:47 +01:00
parent 8ac998ef7d
commit 586fd61781
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 5 additions and 7 deletions

View File

@ -2,7 +2,7 @@
from pathlib import Path from pathlib import Path
from subprocess import run from subprocess import run
from typing import List, Optional from typing import List, Optional, Tuple
def main() -> None: def main() -> None:
@ -14,8 +14,7 @@ def main() -> None:
convert_to_image( convert_to_image(
source=svg, source=svg,
destination=svg.with_name(f"{svg.stem}-{resolution}.png"), destination=svg.with_name(f"{svg.stem}-{resolution}.png"),
width=resolution, resolution=(resolution, resolution),
height=resolution,
) )
else: else:
convert_to_image(source=svg, destination=svg.with_suffix(".png")) convert_to_image(source=svg, destination=svg.with_suffix(".png"))
@ -24,14 +23,13 @@ def main() -> None:
def convert_to_image( def convert_to_image(
source: Path, source: Path,
destination: Path, destination: Path,
width: Optional[int] = None, resolution: Optional[Tuple[int, int]] = None,
height: Optional[int] = None,
) -> None: ) -> None:
"""Convert an SVG to an image with `inkscape`.""" """Convert an SVG to an image with `inkscape`."""
inkscape_args: List[str] = ["inkscape", str(source), "-o", str(destination)] inkscape_args: List[str] = ["inkscape", str(source), "-o", str(destination)]
if width is not None and height is not None: if resolution is not None:
inkscape_args.extend(["-w", str(width), "-h", str(height)]) inkscape_args.extend(["-w", str(resolution[0]), "-h", str(resolution[1])])
run(args=inkscape_args) run(args=inkscape_args)
mat2_image(destination) mat2_image(destination)