Function to Encode Image File to Base64

Contains tips for configurators working with Aware IM
Post Reply
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Function to Encode Image File to Base64

Post by Rennur »

Base 64 encode your images (picture attributes) using function IMAGE_DATA

Embedding picture attribute in HTML:

Code: Select all

<img src='<<IMAGE_DATA(User.Pic)>>' width='100' height='100'>
Embedding Base 64 string :

HTML Image Embedding

Code: Select all

<img alt="Embedded Image" 
  src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />
CSS Image Embedding

Code: Select all

div.image {
  width:100px;
  height:100px;
  background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...);
}

XML Image Embedding Example

Code: Select all

<image>
  <title>An Image</title>
  <link>http://www.your.domain</link>
  <url>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...</url>
</image>
Data URIs can potentially store any type of data, not just images.
Not sure if this function can be used on the document attributes.

HTML CSS Embedding

Code: Select all

<link rel="stylesheet" type="text/css"
  href="data:text/css;base64,LyogKioqKiogVGVtcGxhdGUgKioq..." />
HTML Javascript Embedding

Code: Select all

<script type="text/javascript"
  src="data:text/javascript;base64,dmFyIHNjT2JqMSA9IG5ldyBzY3Jv..."></script>
Cheers
himanshu
Posts: 723
Joined: Thu Jun 19, 2008 6:24 am
Location: India
Contact:

Post by himanshu »

Nice tip Rennur
From,
Himanshu Jain


AwareIM Consultant (since version 4.0)
OS: Windows 10.0, Mac
DB: MYSQL, MSSQL
hpl123
Posts: 2594
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Nice

Post by hpl123 »

Yeah, nice share Rennur and also nice addition to the functions support.
Henrik (V8 Developer Ed. - Windows)
Post Reply