Save image to given path.
(
image: np.ndarray,
output_path: Path,
icc_profile: list[bytes] | None = None,
jpeg_quality: int = 92,
)
| 100 | |
| 101 | |
| 102 | def save_image( |
| 103 | image: np.ndarray, |
| 104 | output_path: Path, |
| 105 | icc_profile: list[bytes] | None = None, |
| 106 | jpeg_quality: int = 92, |
| 107 | ) -> None: |
| 108 | """Save image to given path.""" |
| 109 | output_path.parent.mkdir(parents=True, exist_ok=True) |
| 110 | |
| 111 | extensions_to_format = Image.registered_extensions() |
| 112 | try: |
| 113 | format = extensions_to_format[output_path.suffix.lower()] |
| 114 | except KeyError: |
| 115 | raise ValueError(f"Unsupported output format {output_path.suffix}.") |
| 116 | |
| 117 | with output_path.open("wb") as file_handle: |
| 118 | write_image( |
| 119 | image, |
| 120 | file_handle, |
| 121 | format, |
| 122 | icc_profile=icc_profile, |
| 123 | jpeg_quality=jpeg_quality, |
| 124 | ) |
| 125 | |
| 126 | |
| 127 | def write_image( |
nothing calls this directly
no test coverage detected