2
0
mirror of https://github.com/gchq/CyberChef synced 2025-12-21 02:33:34 +00:00

Add error handling

This commit is contained in:
j433866
2019-03-07 11:19:04 +00:00
parent 4a7ea469d4
commit 1031429550
14 changed files with 348 additions and 144 deletions

View File

@@ -91,23 +91,31 @@ class ResizeImage extends Operation {
throw new OperationError("Invalid file type.");
}
const image = await jimp.read(Buffer.from(input));
if (unit === "Percent") {
width = image.getWidth() * (width / 100);
height = image.getHeight() * (height / 100);
let image;
try {
image = await jimp.read(Buffer.from(input));
} catch (err) {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (unit === "Percent") {
width = image.getWidth() * (width / 100);
height = image.getHeight() * (height / 100);
}
if (ENVIRONMENT_IS_WORKER())
self.sendStatusMessage("Resizing image...");
if (aspect) {
image.scaleToFit(width, height, resizeMap[resizeAlg]);
} else {
image.resize(width, height, resizeMap[resizeAlg]);
if (ENVIRONMENT_IS_WORKER())
self.sendStatusMessage("Resizing image...");
if (aspect) {
image.scaleToFit(width, height, resizeMap[resizeAlg]);
} else {
image.resize(width, height, resizeMap[resizeAlg]);
}
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
return [...imageBuffer];
} catch (err) {
throw new OperationError(`Error resizing image. (${err})`);
}
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
return [...imageBuffer];
}
/**