rsmbl / Resemble.js

Image analysis and comparison

Home Page:http://rsmbl.github.io/Resemble.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(node:9280) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

xiaomizhou66 opened this issue · comments

(node:9280) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at maybeCallback (fs.js:129:9)
at Object.readFile (fs.js:278:14)
at readFile (C:\。。。。。src\utils/login.js:113:18)

const options = {
        output: {
            errorColor: {
                red: 255,
                green: 0,
                blue: 255
            },
            errorType: "movement",
            transparency: 0.3,
            largeImageThreshold: 1200,
            useCrossOrigin: false,
            outputDiff: true
        },
        scaleToSameSize: true,
        ignore: "antialiasing"
        //停止比较一旦确定> 5%不匹配; 这将
        //也启用仅比较模式,不会渲染输出图像;
        //这些组合可以显着提高批处理速度
        //returnEarlyThreshold: 5
    };
    const data = await compareImages(
        //await fs.readFile(`${__dirname}`),
        await fs.readFile('src/img/1.png'),
        await fs.readFile(bgBlurImg),
        options
    );
    //await fs.writeFile("./output.png", data.getBuffer());
    await fs.writeFile(bgDiffImg, data.getBuffer());

Unless you are using something like promise-fs this isn't going to work because you cannot await fs.readFile(). Instead try

 const data = await compareImages(
        fs.readFileSync('src/img/1.png'),
        fs.readFileSync(bgBlurImg),
        options
 );