-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-render-images'
- Loading branch information
Showing
8 changed files
with
109 additions
and
6 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import * as ExifParser from "exif-parser"; | ||
import Utils from "../Utils.js"; | ||
import FileType from "./FileType.js"; | ||
|
||
|
||
/** | ||
|
@@ -42,6 +43,57 @@ const Image = { | |
} | ||
}, | ||
|
||
|
||
/** | ||
* @constant | ||
* @default | ||
*/ | ||
INPUT_FORMAT: ["Raw", "Base64", "Hex"], | ||
|
||
/** | ||
* Render Image operation. | ||
* | ||
* @author n1474335 [[email protected]] | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {html} | ||
*/ | ||
runRenderImage(input, args) { | ||
const inputFormat = args[0]; | ||
let dataURI = "data:"; | ||
|
||
if (!input.length) return ""; | ||
|
||
// Convert input to raw bytes | ||
switch (inputFormat) { | ||
case "Hex": | ||
input = Utils.fromHex(input); | ||
break; | ||
case "Base64": | ||
// Don't trust the Base64 entered by the user. | ||
// Unwrap it first, then re-encode later. | ||
input = Utils.fromBase64(input, null, "byteArray"); | ||
break; | ||
case "Raw": | ||
default: | ||
input = Utils.strToByteArray(input); | ||
break; | ||
} | ||
|
||
// Determine file type | ||
const type = FileType.magicType(input); | ||
if (type && type.mime.indexOf("image") === 0) { | ||
dataURI += type.mime + ";"; | ||
} else { | ||
throw "Invalid file type"; | ||
} | ||
|
||
// Add image data to URI | ||
dataURI += "base64," + Utils.toBase64(input); | ||
|
||
return "<img src='" + dataURI + "'>"; | ||
}, | ||
|
||
}; | ||
|
||
export default Image; |
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 |
---|---|---|
|
@@ -6,6 +6,10 @@ | |
* @license Apache-2.0 | ||
*/ | ||
|
||
body { | ||
overflow: hidden; | ||
} | ||
|
||
#content-wrapper { | ||
position: absolute; | ||
top: 0; | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.