Last active
August 29, 2015 14:06
-
-
Save reustonium/c7d2499d9a092f75032a to your computer and use it in GitHub Desktop.
png in <img>
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
import base64 | |
with open("test.png", "rb") as image_file: | |
encoded_string = base64.b64encode(image_file.read()) | |
img_tag = '<img src="data:image/png;base64,{0}">'.format(encoded_string) | |
print(img_tag) |
I'm clearly missing something here:
Output:
<img src="data:image/png;base64,b'iVBORw0KGgoAAAANSUhEUgAAA2AAAAJACAYAAADrSQUmAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X90n3V99/FXmpRfbSpNEwuUMaToBDl474yVWqcoFCswkChVUae0SHSe2WGV3hNu9EYmnsF2ZMfbDSIiw8nmj9raWZQjFEEPBQV/MM9QpFiwlrZZ2tqSwtqmuf/wUClE/NW8r9A+Hn811/fKlXeST5s+c32v69syNDQ0FAAAAEbcmKYHAAAA2FsIMAAAgCICDAAAoIgAAwAAKCLAAAAAiggwAACAIgIMAACgiAADAAAoIsAAAACKCDAAAIAiAgwAAKCIAAMAACgiwAAAAIoIMAAAgCICDAAAoIgAAwAAKCLAAAAAiggwAACAIgIMAACgiAADAAAoIsAAAACKCDAAAIAiAgwAAKCIAAMAACgiwAAAAIoIMAAAgCICDAAAoIgAAwAAKCLAAAAAiggwAACAIgIMAACgiAADAAAoIs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import base64
with open("yourfile.ext", "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
Via:
http://stackoverflow.com/questions/3715493/encoding-an-image-file-with-base64