I am trying to convert a ".tiff" image to base64 encoded url. However its not wroking in html when I included it in image src.
I have used the following code to get my base64 string
content_type_mapper = {
".jpg": "image/jpg",
".jpeg": "image/jpeg",
".tiff": "image/tiff",
".pdf": "application/pdf",
".png": "image/png",
".tif": "image/tiff"
}
def get_base64(path, content_type):
with open(path, "rb") as img_file:
my_string = base64.b64encode(img_file.read())
my_string = f"data:{content_type_mapper[content_type]};base64," + my_string.decode('ascii')
return my_string
the resulting string from here cant'e be rendered properly in brwoser. I have tried change the content type to image/png, image/application/octet-stream, but didnt work Anyone worked on this before?