MCPcopy Create free account
hub / github.com/CiaraStrawberry/TemporalKit / numpy_array_to_data_uri

Function numpy_array_to_data_uri

scripts/sd-TemporalKit-UI.py:244–263  ·  view source on GitHub ↗
(img_array)

Source from the content-addressed store, hash-verified

242
243
244def 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
265def numpy_array_to_temp_url(img_array):
266 # create a filename for the temporary file

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected