MCPcopy Create free account
hub / github.com/plotly/plotly.py / decode_image_string

Function decode_image_string

tests/test_optional/test_px/test_imshow.py:16–25  ·  view source on GitHub ↗

Converts image string to numpy array.

(image_string)

Source from the content-addressed store, hash-verified

14
15
16def decode_image_string(image_string):
17 """
18 Converts image string to numpy array.
19 """
20 if "png" in image_string[:22]:
21 return np.asarray(Image.open(BytesIO(base64.b64decode(image_string[22:]))))
22 elif "jpeg" in image_string[:23]:
23 return np.asarray(Image.open(BytesIO(base64.b64decode(image_string[23:]))))
24 else:
25 raise ValueError("image string format not recognized")
26
27
28@pytest.mark.parametrize("binary_string", [False, True])

Callers 4

test_originFunction · 0.85
test_imshow_backendFunction · 0.85
test_imshow_compressionFunction · 0.85

Calls 1

openMethod · 0.45

Tested by

no test coverage detected