mirror of
https://github.com/gchq/CyberChef
synced 2025-12-19 17:53:34 +00:00
Tidied up image manipulation ops
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import Magic from "../lib/Magic";
|
||||
import { isImage } from "../lib/FileType";
|
||||
import { toBase64 } from "../lib/Base64.mjs";
|
||||
import jimp from "jimp";
|
||||
|
||||
@@ -76,8 +76,7 @@ class ResizeImage extends Operation {
|
||||
height = args[1];
|
||||
const unit = args[2],
|
||||
aspect = args[3],
|
||||
resizeAlg = args[4],
|
||||
type = Magic.magicFileType(input);
|
||||
resizeAlg = args[4];
|
||||
|
||||
const resizeMap = {
|
||||
"Nearest Neighbour": jimp.RESIZE_NEAREST_NEIGHBOR,
|
||||
@@ -87,7 +86,7 @@ class ResizeImage extends Operation {
|
||||
"Bezier": jimp.RESIZE_BEZIER
|
||||
};
|
||||
|
||||
if (!type || type.mime.indexOf("image") !== 0){
|
||||
if (!isImage(input)) {
|
||||
throw new OperationError("Invalid file type.");
|
||||
}
|
||||
|
||||
@@ -126,16 +125,12 @@ class ResizeImage extends Operation {
|
||||
present(data) {
|
||||
if (!data.length) return "";
|
||||
|
||||
let dataURI = "data:";
|
||||
const type = Magic.magicFileType(data);
|
||||
if (type && type.mime.indexOf("image") === 0){
|
||||
dataURI += type.mime + ";";
|
||||
} else {
|
||||
throw new OperationError("Invalid file type");
|
||||
const type = isImage(data);
|
||||
if (!type) {
|
||||
throw new OperationError("Invalid file type.");
|
||||
}
|
||||
dataURI += "base64," + toBase64(data);
|
||||
|
||||
return "<img src='" + dataURI + "'>";
|
||||
return `<img src="data:${type};base64,${toBase64(data)}">`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user