mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Add opaque background option
This commit is contained in:
parent
e95b7075b9
commit
8e74acbf3e
1 changed files with 13 additions and 1 deletions
|
@ -72,6 +72,11 @@ class ContainImage extends Operation {
|
||||||
"Bezier"
|
"Bezier"
|
||||||
],
|
],
|
||||||
defaultIndex: 1
|
defaultIndex: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Opaque background",
|
||||||
|
type: "boolean",
|
||||||
|
value: true
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -82,7 +87,7 @@ class ContainImage extends Operation {
|
||||||
* @returns {byteArray}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
async run(input, args) {
|
async run(input, args) {
|
||||||
const [width, height, hAlign, vAlign, alg] = args;
|
const [width, height, hAlign, vAlign, alg, opaqueBg] = args;
|
||||||
|
|
||||||
const resizeMap = {
|
const resizeMap = {
|
||||||
"Nearest Neighbour": jimp.RESIZE_NEAREST_NEIGHBOR,
|
"Nearest Neighbour": jimp.RESIZE_NEAREST_NEIGHBOR,
|
||||||
|
@ -115,6 +120,13 @@ class ContainImage extends Operation {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (ENVIRONMENT_IS_WORKER())
|
||||||
self.sendStatusMessage("Containing image...");
|
self.sendStatusMessage("Containing image...");
|
||||||
image.contain(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
|
image.contain(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
|
||||||
|
|
||||||
|
if (opaqueBg) {
|
||||||
|
const newImage = await jimp.read(width, height, 0x000000FF);
|
||||||
|
newImage.blit(image, 0, 0);
|
||||||
|
image = newImage;
|
||||||
|
}
|
||||||
|
|
||||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||||
return [...imageBuffer];
|
return [...imageBuffer];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue