Switch the resolution to be an optional tuple.
This commit is contained in:
parent
8ac998ef7d
commit
586fd61781
12
render.py
12
render.py
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue