(img_array)
| 242 | |
| 243 | |
| 244 | def numpy_array_to_data_uri(img_array): |
| 245 | # convert the array to an image using PIL |
| 246 | img = Image.fromarray(img_array) |
| 247 | |
| 248 | # create a BytesIO object to hold the image data |
| 249 | buffer = io.BytesIO() |
| 250 | |
| 251 | # save the image to the BytesIO object as PNG |
| 252 | img.save(buffer, format='PNG') |
| 253 | |
| 254 | # get the PNG data from the BytesIO object |
| 255 | png_data = buffer.getvalue() |
| 256 | |
| 257 | # convert the PNG data to base64-encoded string |
| 258 | base64_str = base64.b64encode(png_data).decode() |
| 259 | |
| 260 | # combine the base64-encoded string with the image format prefix |
| 261 | data_uri = 'data:image/png;base64,' + base64_str |
| 262 | |
| 263 | return data_uri |
| 264 | |
| 265 | def numpy_array_to_temp_url(img_array): |
| 266 | # create a filename for the temporary file |
nothing calls this directly
no outgoing calls
no test coverage detected