MCPcopy Create free account
hub / github.com/Overv/VulkanTutorial / convert_images

Function convert_images

build_ebook.py:25–57  ·  view source on GitHub ↗

Convert all SVG images to PNGs.

(images_dir: Path, converted_image_dir: Path)

Source from the content-addressed store, hash-verified

23
24
25def convert_images(images_dir: Path, converted_image_dir: Path) -> None:
26 """Convert all SVG images to PNGs."""
27
28 if not converted_image_dir.exists():
29 converted_image_dir.mkdir()
30
31 for source_file in images_dir.glob("*"):
32 if source_file.suffix == ".svg":
33 dest_file = converted_image_dir / source_file.with_suffix(".png").name
34
35 try:
36 subprocess.check_output(
37 [
38 "inkscape",
39 f"--export-filename={dest_file.as_posix()}",
40 source_file.as_posix(),
41 ],
42 stderr=subprocess.STDOUT,
43 )
44 except FileNotFoundError:
45 raise RuntimeError(
46 f"failed to convert {source_file.name} to {dest_file.name}: "
47 "inkscape not installed"
48 )
49 except CalledProcessError as e:
50 raise RuntimeError(
51 f"failed to convert {source_file.name} to {dest_file.name}: "
52 f"inkscape failed: {e.output.decode()}"
53 )
54 else:
55 shutil.copy(source_file, converted_image_dir / source_file.name)
56
57 return converted_image_dir
58
59
60@dataclass

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected