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