MCPcopy Create free account
hub / github.com/apple/ml-sharp / save_image

Function save_image

src/sharp/utils/io.py:102–124  ·  view source on GitHub ↗

Save image to given path.

(
    image: np.ndarray,
    output_path: Path,
    icc_profile: list[bytes] | None = None,
    jpeg_quality: int = 92,
)

Source from the content-addressed store, hash-verified

100
101
102def 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
127def write_image(

Callers

nothing calls this directly

Calls 1

write_imageFunction · 0.85

Tested by

no test coverage detected