up one level
---
2015-04-28

HTML Base-64 Encode an Image to Make a Single HTML File which Contains the Text and Image

I’m really instantly amazed at, and loving, this ability to base-64 encode an image into an html file!

I first discovered this by desiring to find a file format that could save an entire blog post (text and photos) as a single file that is viewable by a web browser.

Using LibreOffice Writer I saved a text+image document in its “HTML Document (.html)” format, and lo and behold it saved it as a single .html file, which contained the text and image and is openable by three major web browsers (chrome, firefox and IE)

Then I googled and found this with some more extreme examples:
(not only images embedded but audio or video)
[ https://www.iandevlin.com/blog/2012/09/html5/html5-media-and-data-uri ]

The real application that I will immediately use this for is the one for which I searched when I found this. I will re-make all my wordpress blog posts from w̶i̶e̶l̶d̶l̶i̶n̶u̶x̶.̶c̶o̶m̶ as single .html files and post them as static files from apache. Thus circumvent WordPress entirely. Which is what I should have done in the first place for my blog!

Finally, pasted here is the entire html source of an html file with an embedded image:

*********************************
START OF source of entire html file with an embedded image
*********************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> </head> <body> <p>Hello, World! Image here:</p> <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAA2CAIAAADlDjbOAAAKNklEQVR4nO2ZWWwbxxnHl7vL5ZLiLZEiZYu6D1uWD9mxE7tCcwBu4CQ90CDtS9MHoy9tgTwELYoiDwGCXkDRh/athXukfTD80j4EaeM2TmIFqmP5iiO7tmyLEn1I1MWbe83u9psdcrk8LbtOW6D9QAyGs7MzP/6/b06ygiBQ/5XG/qcBmtr/yR7cHhnZ4koe0p6w+1E1+JBkidXcubmVxWR+NSOs50QoUVUbw+jkabuHD/mcPZ1t22LBbd3BfwcZcEzN3r14Y2XNoAHTdJpkTCywVL4In7m763+9kODtzOT4lskdXSGf61MhW80UT55PTF9e0BjOWk7btNYvior67szNt87ceGZP3+G9sc3zbYrsxAfXT3+S0JEqqLqD2WTL2GhVhl+C3+Ic716Mw+fw3r6vPjn6CMgKEvrJ8emFZI5lsNecjE2QJeiGdNkaSDJq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sSPyorqeVaeuZ+5tiCxn/+yQt16wSomBBZtewIIVP+iqusypwnxqxP+76SSJsIZwVJ1dXxYSG7JJjFBlSf5MP75TabgPs2IR/wyHHDUtV5ENRZwjESd0Vg+HqzYRr2aRJRb1cX4n02yCsGIJiua228DprcjAjuxqn0smdJ2ugYMBQUpM8VrAQbWxbjdVjqd6qaiyE6FlpKo7ej1UndWSwcHkyHjHHy+scWwFznhCgqAinhWRpKYrB8JOmNmbSUVGIsHKS+poyNHGNbrIqS96YtC7kVc+mMsAXFGE3RFd7dkSnymPmUel5YgZCvEtpKIMD1J4169u9bMjEb6eoTEZ2HO72wVZOzOf pY1Z1CqehY8iLrZige3qrhy1RctOkDARqURFhfcAa29305vHpufvF/eHIAU4GWlW8eBsQnQCRDg6W2+BKCMYAm2sFYj4zspkUKrdQX5vd6vb5Fa3oQDn5Oj3rqWhISIe4SMSEkTrhRSUb+/2EhrKmD8JEGUoSphAqoKkQWxN9Nznkvs+N8jgVjjK/n56SVJ0wmdKCHsh4krWYIVMX9jptNM5UYVtCFGINEJ8B5teSbXZdPREv6+vvent82bJwEajrtde6Ds5u3Hqaspu+FE2OIh+JE9wIwG+FNrlbT8BggwwAR2g7+8JcJu7t9/U/wHg0y9MdBwc9p26kroYzyHNHGglFeE0CqcY4IDhZh4IgAZSAJJ120inY2cX7+Uf4M+EB/h3J+S2f+VA+PN7Oi4s5uaWipcS+HIFVFSQ5uAYmMezhdIhGFAoY0z0d3Ddfn4gDDNJg53SIyMjBvodGvLBB/K3N6TEmriWlyIBl/UuysczHgfdHaxdCj9dMqtB3/9i9y3sf+Cf10du/wRK43GaQOr37QAAAABJRU5ErkJggg=="/></p> <p>That was the image above. The end.</p> </body> </html>
*********************************
END OF source of entire html file with an embedded image
*********************************

And *finally* finally, here’s a screenshot of what the web page looks like. (The web page created when the above html source is copied+pasted and saved in a file and then viewed in a web browser)
Screenshot:




[2019 edit: Moved to: https://investorworker.com/2015/... .html.]