SAS Tip: Images as text - use Base 64 encoding (Daily tip for 2024-Oct-06)


A little-known HTML trick is that you can embed images in an HTML file using a Base 64 representation of an image. For example, a folder open image can be generated using the following text in an HTML page:


<img src="data:image/png;base64,R0lGODlhEAAQAKL/AP//////AMDAwMDAwICAgICAAAAAAAAAACH5BAEAAAIALAAAAAAQABAAAANFKEpMpjAKAkYYTkJqu2sbII6kSCzApXbqM1VrPLiUWpYGFwBF7/+51ID3KwaHReNrlwS+iM0CTRTtTavSjWHL7W41YE0CADs=" border="0" width="4">

 

which will display as: OpenFolder.PNG

 

The width parameter can be used to size the image as desired. Note that the image becomes fuzzy if you use a width that is wider than the original image that you encoded.

 

There are a number of web-sites that will convert images to the Base 64 representation. This Google search provides a sampling.

 

To see the above img tag as an actual image and for a discussion of a parameter/macro driven approach see my blog post The getImage macro: embedded images using text strings

 


Thanks to Don Henderson for sharing this tip on sasCommunity.org.

READ this complete tip   Visit a random SAS tip

Start a topic
About these Tips
A "SAS tip" is a basic unit of information exchange between SAS users. The tips on this board come from sasCommunity.org, from SAS user conferences, from SAS blogs, and from freelance contributions from SAS users like you. We hope that you're able to always learn something new here!


» How you can contribute


Tip-o-meter: 63 tips