Skip to content

Instantly share code, notes, and snippets.

@beckettkev
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beckettkev/1ab58e9101072c17ad39 to your computer and use it in GitHub Desktop.
Save beckettkev/1ab58e9101072c17ad39 to your computer and use it in GitHub Desktop.
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