jimp
jimp copied to clipboard
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?
I get this issue in 0.16.0 but not 0.9.8.
same issue heare (0.16.1)
Same issue with 0.16.1
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);
to
this.bitmap = this.constructor.decoders[_mime](data, {maxMemoryUsageInMB: 2000});
Then I can read the large image. Try this one.
Having the same issue, 10mb jpgs turn into 1.1gb+ ram usage and crash with Error: maxMemoryUsageInMB limit exceeded Happens on newest jimp and the newest windows server
I'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"
Same problem here, any update?
I get this issue in 0.16.0 but not 0.9.8.
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.
This works locally but not working with the live app. How do I fix it
Downgrading to 0.9.8 worked for me as well.
if error is maxResolutionInMP limit exceeded by 36MP
this.bitmap = this.constructor.decoders[_mime](data, {
maxResolutionInMP:400
});
You can fix by overriding the jpeg-js decoder jimp uses as follows:
Jimp.decoders['image/jpeg'] = (data: Buffer) => JPEG.decode(data, { maxMemoryUsageInMB: 1024 });
@hisham where do we put this code? I converted it to regular js like so
Jimp.decoders['image/jpeg'] = (data) => JPEG.decode(data, { maxMemoryUsageInMB: 1024 })
But I get JPEG undefined. Can you help? Thank you
You put it before you use any Jimp operations - i.e.:
import JPEG from 'jpeg-js';
constructor() {
Jimp.decoders['image/jpeg'] = (data: Buffer) => JPEG.decode(data, { maxMemoryUsageInMB: 1024 });
}
myMethod(image: Buffer) {
const jimpImage = await Jimp.read(jpegBuffer);
}
Just a question. How will you handle memory for 'image/tiff' images ?
Is the following correct for NodeJS ?
const jimpJPEG = require('jpeg-js')
const jimpTIFF = require('utif')
jimp.decoders['image/jpeg'] = (data) => {
return jimpJPEG.decode(data, {
maxMemoryUsageInMB: 1024
})
}
jimp.decoders['image/tiff'] = (data) => {
var ifds = jimpTIFF.decode(data, {
maxMemoryUsageInMB: 1024
})
var page = ifds[0]
jimpTIFF.decodeImages(data, ifds)
var rgba = jimpTIFF.toRGBA8(page)
return {
data: Buffer.from(rgba),
width: page.t256[0],
height: page.t257[0]
}
}
Any update? problem is here: node_modules/@jimp/core/dist/utils/image-bitmap.js -> node_modules/jpeg-js/lib/decoder.js
Having this same problem too. Is there any major difference between the 0.9 and 0.16 versions?
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:
throw new Error(`maxResolutionInMP limit exceeded by ${exceededAmount}MP`);
^
Error: maxResolutionInMP limit exceeded by 466MP
at constructor.parse (/Users/me/projects/my-app/node_modules/jpeg-js/lib/decoder.js:738:21)
at Object.decode (/Users/me/projects/my-app/node_modules/jpeg-js/lib/decoder.js:1109:11)
at Object.Jimp.decoders.image/jpeg (/Users/me/projects/my-app/src/ingest-images.js:11:14)
at Jimp.parseBitmap (/Users/me/projects/my-app/node_modules/@jimp/core/dist/utils/image-bitmap.js:196:53)
at Jimp.parseBitmap (/Users/me/projects/my-app/node_modules/@jimp/core/dist/index.js:431:32)
at /Users/me/projects/my-app/node_modules/@jimp/core/dist/index.js:373:15
The solution was to override the maxResolutionInMP
value in addition to the memory value. This works for me:
const Jimp = require('jimp')
// add support for very large image files
const JPEG = require('jpeg-js')
Jimp.decoders['image/jpeg'] = (data) => JPEG.decode(data, {
maxMemoryUsageInMB: 6144,
maxResolutionInMP: 600
})
same problem, still happening for 16mb jpegs
tomprogers
hack worked great for me, but having jimp use 200mb of memory for a 10mb jpeg is not ideal
this is lots of fun with 100mb pro photos
i found the solutions above would only partially work and further transforms like crop
would error
This is what worked for me
const cachedJpegDecoder = Jimp.decoders['image/jpeg']
Jimp.decoders['image/jpeg'] = (data) => {
const userOpts = { maxMemoryUsageInMB: 1024 }
return cachedJpegDecoder(data, userOpts)
}
What should be the maximum size range (px or size) of an image? How can I calculate the range of image sizes?
I have tried to read buffer of an 2.5MB image and got this error.
try using https://github.com/lovell/sharp
try using https://github.com/lovell/sharp
Yup, I have migrated to https://sharp.pixelplumbing.com/