Create a gist now

Instantly share code, notes, and snippets.

Embed
var img = document.createElement("img");
img.src = "https://mycompany.sharepoint.com/lists/publishingimages/icons/home.png";
var imgWidth = img.width;
var imgHeight = img.height;
var canvas = document.createElement('canvas');
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
//remember if you want to use JPG, include the 'e' (image/jpeg)
var base64 = canvas.toDataURL("image/png");
var img_html = "<img src='" + base64 + "' alt='icon image'/>";
Office.context.document.setSelectedDataAsync(img_html, {coercionType: "html"}, function (asyncResult) {
if (asyncResult.status == "failed") {
write('Error: ' + asyncResult.error.message);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment