MCPcopy Create free account
hub / github.com/dcharatan/flowmap / encode_image

Function encode_image

paper/svg_tools.py:15–23  ·  view source on GitHub ↗
(
    image: Float[Tensor, "3 height width"],
    image_format: Literal["png", "jpeg"] = "png",
)

Source from the content-addressed store, hash-verified

13
14
15def encode_image(
16 image: Float[Tensor, "3 height width"],
17 image_format: Literal["png", "jpeg"] = "png",
18) -> str:
19 stream = BytesIO()
20 Image.fromarray(prep_image(image)).save(stream, image_format)
21 stream.seek(0)
22 base64str = codecs.encode(stream.read(), "base64").rstrip()
23 return f"data:image/{image_format};base64,{base64str.decode('ascii')}"
24
25
26def save_svg(fig: svg.SVG, path: Path) -> None:

Callers

nothing calls this directly

Calls 1

prep_imageFunction · 0.90

Tested by

no test coverage detected