This is the same as issue 643. However, the latter is closed and seems like it is dead despite people experiencing this issue still.
Jimp.read loads an image from a URL correctly.
Trying to read some images from certain URLs fails, throwing Error: Could not find MIME for Buffer <null>
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.
Repo with a simple script to reproduce the error: https://github.com/codan84/jimp-bug
{ 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' }
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)
})
Have same problem. Problematic images downloaded on local disk with requst module make this error in jimp too. But are not have visible promplems.
I try use GM for edited this images. It don't read them too. Show this error:
Error: Command failed: gm composite: Improper image header
If i give created by me 100% good images , he dont worked.
Maybe i did something wrong , but if i use good images with JIMP, i have wanting results.
How i can get images from internet and use them with JIMP without errors ?
I'm facing the same issue using node-vibrant, a library that uses Jimp and the axios trick is working like a charm!
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 <3.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);
});
}
Please make a PR so we can all benefit from your code :) A comment helps very few but a PR can help many
@SaWey
jimp does not handle this, neither does phin <3.1.0
Either upgrading the phin library ( #ethanent/phin#20) or handling this in the jimp core 'loadFromURL' should do the trick.
But what i can't use downloaded images from this urls. Are not looking broken or something. Opened with any program for images viewer.
Please make a PR so we can all benefit from your code :) A comment helps very few but a PR can help many
@SaWey
Since there were 2 options I didn't know what way to go, but I have created a pull request which allows following redirects without upgrading phin.
If phin supports this in a later version it think it makes sense to upgrade
It probably does make sense, but it also makes sense to always follow redirects by default.
Phin >=3.1.0 requires the flag followRedirects to be set in order to follow redirects.
:rocket: Issue was released in v0.9.3 :rocket:
:rocket: Issue was released in v0.9.3 :rocket:
Getting same in still now
Node 13.8.0
NPM 6.13.6
jimp: ^0.93
{ Error: Could not find MIME for Buffer
at Jimp.parseBitmap (../node_modules/@jimp/core/dist/utils/image-bitmap.js:106:15)
at Jimp.parseBitmap (../node_modules/@jimp/core/dist/index.js:521:32)
at new Jimp (../node_modules/@jimp/core/dist/index.js:474:13)
at _construct (../node_modules/@babel/runtime/helpers/construct.js:30:21)
at ../node_modules/@jimp/core/dist/index.js:1016:32
at new Promise (
at Function.Jimp.read (../node_modules/@jimp/core/dist/index.js:1015:10)
{
methodName: 'constructor'
}
I still get this error
Node v13.5.0
NPM v6.13.7
jimp ^0.93
Add logo error Error: Could not find MIME for Buffer <null>
at Jimp.parseBitmap (C:\Users\burakkujakku\Documents\GIT\conect\conect-api\node_modules\@jimp\core\dist\utils\image-bitmap.js:106:15)
at Jimp.parseBitmap (C:\Users\burakkujakku\Documents\GIT\conect\conect-api\node_modules\@jimp\core\dist\index.js:521:32)
at C:\Users\burakkujakku\Documents\GIT\conect\conect-api\node_modules\@jimp\core\dist\index.js:463:15
at C:\Users\burakkujakku\Documents\GIT\conect\conect-api\node_modules\@jimp\core\dist\index.js:205:14
at C:\Users\burakkujakku\Documents\GIT\conect\conect-api\node_modules\@jimp\core\dist\request.js:66:9
at IncomingMessage.<anonymous> (C:\Users\burakkujakku\Documents\GIT\conect\conect-api\node_modules\phin\lib\phin.compiled.js:1:2100)
at IncomingMessage.emit (events.js:317:22)
at endReadableNT (_stream_readable.js:1215:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
methodName: 'constructor'
}
My codes use to add logo-img to picture
Jimp.read(imgRaw)
.then(tpl =>
Jimp.read(imgLogo)
.then(logoTpl => {
let axios_x = tpl.bitmap.width;
let axios_y = tpl.bitmap.height;
logoTpl.opacity(0.2);
return tpl.composite(logoTpl, axios_x - 134, axios_y - 86, [Jimp.BLEND_DESTINATION_OVER, 0.2, 0.2]);
})
)
.then(tpl => {
tpl.quality(100).write(imgExported)
})
.then(tpl => {
console.log('exported file: ' + imgExported);
})
.catch(err => {
console.error('Add logo error', err);
})
I'm also seeing this "Error: Could not find MIME for Buffer
I'm also seeing this "Error: Could not find MIME for Buffer " error. the images are buffers.
So, after much digging and experimentation I rewrote all of my code that creates the local files and all of the invocations of jimp to process them to absolutely guarantee there was no possibility of any async race conditions or any possibility of reusing intermediate files. That _appears_ to have resolved my issues as far as I can tell under test.
I also face this issue.. Any news on this old issue?
Same here...
Jimp 0.16.1
Node 10.13.0
After rewriting all of my code that calls jimp as noted above, I no longer have these problems. I believe I can now confirm that the issues I was having were race conditions between jimp code and the file system.
Hi all !
I'm facing the same problem with JIMP.
I have Node-red dockerized and this is what i got when i try to upload an image from URL.

Also i have this JIMP version inside my package.json file.

Any suggestions?.
Regards!
Facing the same issue trying to read from a local file.
JIMP version "jimp": "^0.16.1",
Facing the same issue trying to read from a local file.
JIMP version"jimp": "^0.16.1",
Hi !
I could upgrade the JIMP version and now i can upload the image correctly.
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)
Maybe this is of help to others. I got this error and solved it in my script. In my case it was an async bug in my code. When doing batch processing I was trying to run jimp.read() on an image file that was not found, incomplete or empty at the run time.
Most helpful comment
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-axiosbranch 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:
Working: