javascriptopencvjimp

Error: Could not find MIME for Buffer <null> while using Jimp to save the buffer of cv.Mat()


Here is the snippet of my code which produce the error:

let mat = cv.Mat.zeros(cnn_size, cnn_size, 3);
savepath = "path/to/saved/image.jpg"
let bf = Buffer.from(mat.data);
Jimp.read(bf).then(data => {
    console.log(data);
    return data.resize(cnn_size, cnn_size).write(savepath);
}).catch(err => {
    console.error(err);
});

Running the code caused this error: (node:2152) UnhandledPromiseRejectionWarning: Error: Could not find MIME for Buffer <null>.


Solution

  • I had the same issue with a project I was working on. A combination of axios and jimp.read worked for me.

    axios({
    method: 'get',
    url: failingImageUrl,
    responseType: 'arraybuffer'
    })
    .then(function ({data: imageBuffer}) {
     return jimp.read(imageBuffer)
    })
    

    Source https://github.com/oliver-moran/jimp/issues/775#issuecomment-521938738