-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Builds a html image element for images using absolute paths. | ||
* Currently this only supports .png files. | ||
* @param {HTMLElement} parent HTML element to insert the image into. Image will be appended to the bottom of the element. | ||
* @param {string} filePath Full path to the image | ||
* @param {string} id HTML id if required | ||
* @param {string} htmlClass HTML class if required | ||
* @param {string} style HTML styling if required | ||
* @param {string} alt HTML image alt if required | ||
*/ | ||
function buildImageSync(parent, filePath, id, htmlClass, style, alt) { | ||
const fs = require("fs"); | ||
var imgBase64 = fs.readFileSync(filePath).toString("base64"); | ||
insertImage(parent, imgBase64, id, htmlClass, style, alt); | ||
} | ||
|
||
/** | ||
* Builds a html image element for images using absolute paths. | ||
* Currently this only supports .png files. | ||
* This runs asychronously. | ||
* @param {HTMLElement} parent HTML element to insert the image into. Image will be appended to the bottom of the element. | ||
* @param {string} filePath Full path to the image | ||
* @param {string} id HTML id if required | ||
* @param {string} htmlClass HTML class if required | ||
* @param {string} style HTML styling if required | ||
* @param {string} alt HTML image alt if required | ||
*/ | ||
function buildImage(parent, filePath, id, htmlClass, style, alt) { | ||
const fs = require("fs"); | ||
fs.readFile(filePath, (err, data) => { | ||
insertImage(parent, data.toString("base64"), id, htmlClass, style, alt); | ||
}); | ||
} | ||
|
||
/** | ||
* Builds and inserts html image element. | ||
* Currently this only supports .png files. | ||
* WARNING: This is not meant for use outside the function buildImage. | ||
* @param {HTMLElement} parent HTML element to insert the image into. Image will be appended to the bottom of the element. | ||
* @param {string} filePath Full path to the image | ||
* @param {string} id HTML id if required | ||
* @param {string} htmlClass HTML class if required | ||
* @param {string} style HTML styling if required | ||
* @param {string} alt HTML image alt if required | ||
*/ | ||
function insertImage(parent, imgBase64, id, htmlClass, style, alt) { | ||
var imgHtml = | ||
'<img id="' + | ||
id + | ||
'" class="' + | ||
htmlClass + | ||
'" style="' + | ||
style + | ||
'" alt="' + | ||
alt + | ||
'" src="data:image/png;base64,' + | ||
imgBase64 + | ||
'" />'; | ||
parent.insertAdjacentHTML("beforeend", imgHtml); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
942daa0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #4