I have a file stream of an image in Python:
\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x04\x87...
How do I convert this to a data URI?
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAU...'
Encode it in base64, then remove the newlines.
>>> '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x04\x87...'.encode('base64').replace('\n', '')
'iVBORw0KGgoAAAANSUhEUgAABI....'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With