jimp: Error: Could not find MIME for Buffer

This is the same as issue 643. However, the latter is closed and seems like it is dead despite people experiencing this issue still.

Expected Behavior

Jimp.read loads an image from a URL correctly.

Current Behavior

Trying to read some images from certain URLs fails, throwing Error: Could not find MIME for Buffer <null>

Failure Information (for bugs)

Whilst certain images load correctly, other consistently fail (a failing url will always fail, without exception).
Example failing URL: https://s-media-cache-ak0.pinimg.com/736x/c9/8f/e1/c98fe17dc7de72bb29c34a0c79ef5762.jpg

Trying to Jimp.read it 1000 times gives:

Called jimp.read() 1000 times.
  Failed: 1000.
  Succeeded: 0.

Steps to Reproduce

Repo with a simple script to reproduce the error: https://github.com/codan84/jimp-bug

Context

  • Jimp Version: 0.6.4
  • Operating System: OSX 10.14.3
  • Node version: v10.16.2

Failure Logs

{ Error: Could not find MIME for Buffer <null>
    at Jimp.parseBitmap (/Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/utils/image-bitmap.js:108:15)
    at Jimp.parseBitmap (/Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/index.js:498:32)
    at /Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/index.js:440:15
    at /Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/index.js:168:14
    at /Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/request.js:56:9
    at IncomingMessage.<anonymous> (/Users/gruszd01/workspace/jimp-bug/node_modules/phin/lib/phin.compiled.js:1:2100)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19) methodName: 'constructor' }

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 9
  • Comments: 33 (3 by maintainers)

Commits related to this issue

Most upvoted comments

It’s also worth mentioning that reading the same image using an external request library (I used axios) into a buffer and then loading that same image to jimp from a buffer works.
An example of that is in use-axios branch of the repo I linked above.
This would only mean that there’s an issue with whatever is used for http requests in jimp…

Not working:

jimp.read(failingImageUrl)

Working:

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

This is happening when the image requested has a redirect response. Your sample image is returning this response: https://s-media-cache-ak0.pinimg.com/736x/c9/8f/e1/c98fe17dc7de72bb29c34a0c79ef5762.jpg

accept-ranges: bytes
content-length: 0
date: Wed, 04 Sep 2019 10:02:45 GMT
location: https://i.pinimg.com/736x/c9/8f/e1/c98fe17dc7de72bb29c34a0c79ef5762.jpg
retry-after: 0
status: 301
vary: Origin
x-cdn: fastly

jimp does not handle this, neither does phin ❤️.1.0 Either upgrading the phin library ( #https://github.com/ethanent/phin/issues/20) or handling this in the jimp core ‘loadFromURL’ should do the trick.

For now, I updated this code in 'core/dist/index.js to solve my problem:

function loadFromURL(options, cb) {
  (0, _request.default)(options, function (err, response, data) {
    if (err) {
      return cb(err);
    }

    if(response.headers.hasOwnProperty('location') ){
      options.url = response.headers['location'];
      return loadFromURL(options, cb);
    }

    if (_typeof(data) === 'object' && Buffer.isBuffer(data)) {
      return cb(null, data);
    }

    var msg = 'Could not load Buffer from <' + options.url + '> ' + '(HTTP: ' + response.statusCode + ')';
    return new Error(msg);
  });
}

I’m also getting this issue, perhaps worth re-opening?

Error: Could not find MIME for Buffer <null>
    at Jimp.call (/Users/jameshomer/Projects/fokus/node_modules/@jimp/core/src/utils/image-bitmap.js:156:15)
    at Jimp.parseBitmap (/Users/jameshomer/Projects/fokus/node_modules/@jimp/core/src/index.js:400:17)
    at new Jimp (/Users/jameshomer/Projects/fokus/node_modules/@jimp/core/src/index.js:355:12)

I also face this issue… Any news on this old issue?

I’m also seeing this “Error: Could not find MIME for Buffer <null>” error sporadically one time in about 5 or so. In my case, the images are local files (no network access involved). I’m working to extract a small test case from the larger test suite to submit for repro. Current versions of jimp 0.10.2 and node 13.12.0