Last active
July 11, 2023 01:42
-
-
Save bergantine/1171682 to your computer and use it in GitHub Desktop.
Python Image Encoding in Data URI Scheme Base 64. #python #base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_uri = open("sample.png", "rb").read().encode("base64").replace("\n", "") | |
# HTML Image Element | |
img_tag = '<img alt="" src="data:image/png;base64,{0}">'.format(data_uri) | |
print img_tag | |
# CSS Background Image | |
css = 'background-image: url(data:image/png;base64,{0});'.format(data_uri) | |
print css |
thx I was the next guy googling this
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could be useful to the next guy googling this: