Tidied up 'Generate Image' operation

This commit is contained in:
n1474335 2020-03-13 16:35:19 +00:00
parent 032c7f529a
commit 1a5dae76c2
2 changed files with 10 additions and 11 deletions

View File

@ -394,8 +394,8 @@
"name": "Multimedia", "name": "Multimedia",
"ops": [ "ops": [
"Render Image", "Render Image",
"Generate Image",
"Play Media", "Play Media",
"Generate Image",
"Optical Character Recognition", "Optical Character Recognition",
"Remove EXIF", "Remove EXIF",
"Extract EXIF", "Extract EXIF",

View File

@ -25,9 +25,9 @@ class GenerateImage extends Operation {
this.name = "Generate Image"; this.name = "Generate Image";
this.module = "Image"; this.module = "Image";
this.description = "Generate an Image using the input as pixel values."; this.description = "Generates an image using the input as pixel values.";
this.infoURL = ""; this.infoURL = "";
this.inputType = "byteArray"; this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer"; this.outputType = "ArrayBuffer";
this.presentType = "html"; this.presentType = "html";
this.args = [ this.args = [
@ -42,7 +42,7 @@ class GenerateImage extends Operation {
"value": 8, "value": 8,
}, },
{ {
"name": "Pixels per Row", "name": "Pixels per row",
"type": "number", "type": "number",
"value": 64, "value": 64,
} }
@ -55,15 +55,14 @@ class GenerateImage extends Operation {
* @returns {ArrayBuffer} * @returns {ArrayBuffer}
*/ */
async run(input, args) { async run(input, args) {
const mode = args[0]; const [mode, scale, width] = args;
const scale = args[1]; input = new Uint8Array(input);
const width = args[2];
if (scale <= 0) { if (scale <= 0) {
throw new OperationError("Pixel Scale Factor needs to be > 0"); throw new OperationError("Pixel Scale Factor needs to be > 0");
} }
if (width <= 0) { if (width <= 0) {
throw new OperationError("Pixels per Row needs to be > 0"); throw new OperationError("Pixels per Row needs to be > 0");
} }
@ -85,7 +84,7 @@ class GenerateImage extends Operation {
const image = await new jimp(width, height, (err, image) => {}); const image = await new jimp(width, height, (err, image) => {});
if (isWorkerEnvironment()) if (isWorkerEnvironment())
self.sendStatusMessage("Generate image from data..."); self.sendStatusMessage("Generating image from data...");
if (mode === "Bits") { if (mode === "Bits") {
let index = 0; let index = 0;
@ -150,7 +149,7 @@ class GenerateImage extends Operation {
if (scale !== 1) { if (scale !== 1) {
if (isWorkerEnvironment()) if (isWorkerEnvironment())
self.sendStatusMessage("Scale image..."); self.sendStatusMessage("Scaling image...");
image.scaleToFit(width*scale, height*scale, jimp.RESIZE_NEAREST_NEIGHBOR); image.scaleToFit(width*scale, height*scale, jimp.RESIZE_NEAREST_NEIGHBOR);
} }