Jimp returning wrong mime type

327 Views Asked by At

I wrote a bitmap parser that should return jimp object (image) and im getting error "Unsupported MIME type: audio/mpeg"

Here's the code:

var mid = Buffer.from(mapbitmap, 'base64');
var image2 = await Jimp.read(mid);

the mapbitmap is the bitmap that im trying to parse, it's not empty or something.

Detailed error:

Error: Unsupported MIME type: audio/mpeg
    at Jimp.throwError (D:\FrostX\Develop\javascript\sandbox\node_modules\@jimp\utils\dist\index.js:21:13)
    at Jimp.parseBitmap (D:\FrostX\Develop\javascript\sandbox\node_modules\@jimp\core\dist\utils\image-bitmap.js:159:32) {
  methodName: 'constructor'
}

I don't know what to do about this, I just started learning javascript yesterday and basically don't know how to fix this,

It should be returning image instead of audio.

1

There are 1 best solutions below

1
giosan On

from the error it looks like Jimp is reading your bitmap as an audio file, to fix it you need to parse your data as an image:

  const Jimp = require('jimp');

  var mid = Buffer.from(mapbitmap, 'base64');
  var image = await Jimp.read(mid, { mime: Jimp.MIME_BMP });

this snippet should work