gustavla / vzlog

Python tool for logging rich content, particularly plots and images.
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

integrate image files in HTML? #1

Open mheilman opened 9 years ago

mheilman commented 9 years ago

It might be more convenient to have the plot image files in the HTML output as base64, either as the default or as an option (they could always be separated out by right-clicking and saving in a browser), rather than having an index.html with several separate png and/or svg files.

Converting an image file to base64 in python would be something like this:

encoded_string = base64.b64encode(image_file.read())

And then embedding the image in HTML would be like this:

("<img src=\"data:{mimetype};base64,{base_64_data}\"/>"
 .format(mimetype="image/png", base_64_data=encoded_string))

Just a thought.

http://stackoverflow.com/questions/3715493/encoding-an-image-file-with-base64 http://stackoverflow.com/questions/1207190/embedding-base64-images

gustavla commented 9 years ago

That's a great idea and I have actually been thinking about this, at least as an option. I have a branch that's trying to tap into IPython's display function, which would make it possible to embed not just images, but whatever IPython supports. I'll hold off on implementing embedded images manually until that branch matures, since I might be able to get it for free through IPython.

Really glad to get some input from a front-end expert on this, @mheilman :smiley:

mheilman commented 9 years ago

haha :-)