Pillow is a library that offers image processing capabilities
See Pillow documentation for more details
Split the data string into metadata and data
[meta, data] = inputs['file'].split(";base64,")
Decode the base64 string into a file type
file_data = io.BytesIO(base64.b64decode(data))
and then convert to Pillow Image
img = Image.open(file_data)
To view the new image, the image must be converted to a base64 string. Use img.save()
to save the image to the io.BytesIO()
. Then encode the saved image in buffer
into a base64 string using b64encode
buffer = io.BytesIO() img.save(buffer, format=img.format) encoded_data = metadata + base64.b64encode(buffer.getvalue()).decode()
Return to outputs using the HTML img tag, where src is the source of the image (ie. the encoded image data)
return { "img": "", }
Get the img
variable from the outputs
keyword
{{ outputs.img }}
Copyright © MecSimCalc 2024
Terms | Privacy