0

Within my node application I am using Jimp and my code is working but when repeating it multiple times, randomly an error is thrown and I cannot understand why:

The code is just looping. It's working, i just get the error message sometimes without any explainable reason.

const Jimp = require("jimp");

function takeScreenshot() {
    x=35; y=11; width=180; height=17;
    img = robot.screen.capture(x, y, width, height).image;
    new Jimp({data: img, width, height}, (err, image) => {
        image.write('test-screenshot.png');
    });    
    console.log("Saved...");
}
  
async function convertScreenshot() {
    try {
    console.log("converting...");
    const image = await Jimp.read
    ('test-screenshot.png');
    image.contrast(0.8)
    .write('test-contrastScreenshot.png');
    } catch(error) {
        console.log(error);
    }
}

function foo() {
    takeScreenshot();
    convertScreenshot();
    setTimeout(foo, 2000);
}
foo();

error message:

Saved screenshot...
converting screenshot...
Saved screenshot...
converting screenshot...
Saved screenshot...
Error: Could not find MIME for Buffer <null>
    at Jimp.parseBitmap (\node_modules\@jimp\core\dist\utils\image-bitmap.js:187:15)
    at Jimp.parseBitmap (\node_modules\@jimp\core\dist\index.js:431:32)
    at \node_modules\@jimp\core\dist\index.js:373:15
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3) {
  methodName: 'constructor'
}
Saved screenshot...
converting screenshot...
Saved screenshot...
converting screenshot...
Saved screenshot...
converting screenshot...

0 Answers0