jimp: Failing to read large files
I’m trying to use Jimp to process images that are about 70-100 MB in size. However, I get the following error
// image is 87.7 MB
Jimp.read('big-image', (err, img) => {
console.log(err)
})
> Error: maxMemoryUsageInMB limit exceeded by at least 226MB
Is there any way around this?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 17
- Comments: 30
Commits related to this issue
- temp: use jimp get stuck at https://github.com/oliver-moran/jimp/issues/915 — committed to 1zumii/image-filter by 1zumii 2 years ago
- Disable Jimp JPEG decoder memory limit It's capped at some fixed value, which botches loading images of larger resolutions for no good reasons This disables the limit in the deferred image manipualti... — committed to askmeaboutlo0m/postybirb-plus by askmeaboutlo0m a year ago
- Disable Jimp JPEG decoder memory limit It's capped at some fixed value, which botches loading images of larger resolutions for no good reasons This disables the limit in the deferred image manipualti... — committed to askmeaboutlo0m/postybirb-plus by askmeaboutlo0m a year ago
- Disable Jimp JPEG decoder memory limit (#215) It's capped at some fixed value, which botches loading images of larger resolutions for no good reasons This disables the limit in the deferred image m... — committed to mvdicarlo/postybirb-plus by askmeaboutlo0m 10 months ago
i found the solutions above would only partially work and further transforms like
cropwould errorThis is what worked for me
I have same problem. So I tried fix something. [(https://developer.aliyun.com/mirror/npm/package/jpeg-js)] On this site, there are maxMemoryUsageInMB option on decode function.
And I change \node_modules@jimp\core\dist\utils\image-bitmap.js:196 line.
this.bitmap = this.constructor.decoders[_mime](data);tothis.bitmap = this.constructor.decoders[_mime](data, {maxMemoryUsageInMB: 2000});Then I can read the large image. Try this one.
The solutions described here weren’t working for me. I tried 1024, 2048, even 4096. In every case, the error said the limit has been exceeded by 466MP:
The solution was to override the
maxResolutionInMPvalue in addition to the memory value. This works for me:You can fix by overriding the jpeg-js decoder jimp uses as follows:
Jimp.decoders['image/jpeg'] = (data: Buffer) => JPEG.decode(data, { maxMemoryUsageInMB: 1024 });Same issue with
0.16.1I’m having the same issue.
Our problem has only been reported from users with a specific phone model (Huawei P30). We’re using JIMP to compress and resize images taken from a native mobile application.
Running version:
"jimp": "^0.16.0"I get this issue in 0.16.0 but not 0.9.8.
@kane-mason’s solution if you’re using typescript you might have to add
<any>pre to jimp.decoders[“image/jpeg”] as the default constructor only expects one argument.try using https://github.com/lovell/sharp
Just a question. How will you handle memory for ‘image/tiff’ images ?
Is the following correct for NodeJS ?
You put it before you use any Jimp operations - i.e.:
Downgrading to 0.9.8 worked for me as well.
Yup, I have migrated to https://sharp.pixelplumbing.com/
I have tried to read buffer of an 2.5MB image and got this error.
This works locally but not working with the live app. How do I fix it