map-machine/roentgen/raster.py
2021-07-07 23:47:56 +03:00

24 lines
598 B
Python

import os
import subprocess
from pathlib import Path
from typing import List
def rasterize(
from_: Path, to_: Path, area: str = "", dpi: float = 90
) -> None:
"""
Make PNG image out of SVG using Inkscape.
"""
inkscape: str = "inkscape"
if "INKSCAPE_BIN" in os.environ:
inkscape: str = os.environ["INKSCAPE_BIN"]
commands: List[str] = [inkscape]
commands += ["--export-png", to_.absolute()]
commands += ["--export-dpi", str(dpi)]
if area:
commands += ["--export-area", area]
commands += [from_.absolute()]
subprocess.run(commands)