mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 00:48:31 +01:00
Add resize algorithm option
This commit is contained in:
parent
9f4aa0a123
commit
0d86a7e427
1 changed files with 23 additions and 2 deletions
|
@ -48,6 +48,18 @@ class ResizeImage extends Operation {
|
||||||
name: "Maintain aspect ratio",
|
name: "Maintain aspect ratio",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
value: false
|
value: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Resizing algorithm",
|
||||||
|
type: "option",
|
||||||
|
value: [
|
||||||
|
"Nearest Neighbour",
|
||||||
|
"Bilinear",
|
||||||
|
"Bicubic",
|
||||||
|
"Hermite",
|
||||||
|
"Bezier"
|
||||||
|
],
|
||||||
|
defaultIndex: 1
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -62,8 +74,17 @@ class ResizeImage extends Operation {
|
||||||
height = args[1];
|
height = args[1];
|
||||||
const unit = args[2],
|
const unit = args[2],
|
||||||
aspect = args[3],
|
aspect = args[3],
|
||||||
|
resizeAlg = args[4],
|
||||||
type = Magic.magicFileType(input);
|
type = Magic.magicFileType(input);
|
||||||
|
|
||||||
|
const resizeMap = {
|
||||||
|
"Nearest Neighbour": jimp.RESIZE_NEAREST_NEIGHBOR,
|
||||||
|
"Bilinear": jimp.RESIZE_BILINEAR,
|
||||||
|
"Bicubic": jimp.RESIZE_BICUBIC,
|
||||||
|
"Hermite": jimp.RESIZE_HERMITE,
|
||||||
|
"Bezier": jimp.RESIZE_BEZIER
|
||||||
|
};
|
||||||
|
|
||||||
if (!type || type.mime.indexOf("image") !== 0){
|
if (!type || type.mime.indexOf("image") !== 0){
|
||||||
throw new OperationError("Invalid file type.");
|
throw new OperationError("Invalid file type.");
|
||||||
}
|
}
|
||||||
|
@ -74,9 +95,9 @@ class ResizeImage extends Operation {
|
||||||
height = image.getHeight() * (height / 100);
|
height = image.getHeight() * (height / 100);
|
||||||
}
|
}
|
||||||
if (aspect) {
|
if (aspect) {
|
||||||
image.scaleToFit(width, height);
|
image.scaleToFit(width, height, resizeMap[resizeAlg]);
|
||||||
} else {
|
} else {
|
||||||
image.resize(width, height);
|
image.resize(width, height, resizeMap[resizeAlg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||||
|
|
Loading…
Reference in a new issue