@@ -16,7 +16,9 @@ def decode_image_string(image_string):
16
16
"""
17
17
Converts image string to numpy array.
18
18
"""
19
- if "png" in image_string [:22 ]:
19
+ if "webp" in image_string [:23 ]:
20
+ return np .asarray (Image .open (BytesIO (base64 .b64decode (image_string [23 :]))))
21
+ elif "png" in image_string [:22 ]:
20
22
return np .asarray (Image .open (BytesIO (base64 .b64decode (image_string [22 :]))))
21
23
elif "jpeg" in image_string [:23 ]:
22
24
return np .asarray (Image .open (BytesIO (base64 .b64decode (image_string [23 :]))))
@@ -62,7 +64,7 @@ def test_automatic_zmax_from_dtype():
62
64
63
65
64
66
@pytest .mark .parametrize ("binary_string" , [False , True ])
65
- @pytest .mark .parametrize ("binary_format" , ["png" , "jpg" ])
67
+ @pytest .mark .parametrize ("binary_format" , ["webp" , " png" , "jpg" ])
66
68
def test_origin (binary_string , binary_format ):
67
69
for i , img in enumerate ([img_rgb , img_gray ]):
68
70
fig = px .imshow (
@@ -76,7 +78,9 @@ def test_origin(binary_string, binary_format):
76
78
# The equality below does not hold for jpeg compression since it's lossy
77
79
assert np .all (img [::- 1 ] == decode_image_string (fig .data [0 ].source ))
78
80
if binary_string :
79
- if binary_format == "jpg" :
81
+ if binary_format == "webp" :
82
+ assert fig .data [0 ].source [:15 ] == "data:image/webp"
83
+ elif binary_format == "jpg" :
80
84
assert fig .data [0 ].source [:15 ] == "data:image/jpeg"
81
85
else :
82
86
assert fig .data [0 ].source [:14 ] == "data:image/png"
0 commit comments