Create a new PNG file
Error: No matching constructor overloading was found. Please see the docs for how to call the Jimp constructor.
let pixelData = new Uint8Array(dataset.byteArray.buffer, pixelDataElement.dataOffset, pixelDataElement.length);
new Jimp({ data: pixelData, width: columns, height: rows }, (err, image) => {
console.log(err);
console.log(image);
});
Have you tried makeing pixelData into a buffer? Has this worked before?
It's the first time I'm using Jimp, just following the docs and APIs. I just tried with pixelData.buffer and it doesn't work, same error.
This is the code uses to determine if the data is a image buffer
https://github.com/oliver-moran/jimp/blob/master/packages/core/src/index.js#L95
it looks like you may have the wrong size.
@hipstersmoothie I see, indeed my image is a 1 channel (white/black) with non-alpha. How could I do it in this case? Maybe it would be good to update the error message into something more explicit like : "Received xxx bytes but expecting yyy bytes" or "Wrong image size".
Thanks for your help
Could I get a sample repo for this? Since there is no image this is harder to test
Unfortunately I'm working with some sensitive data and cannot share the image, but I guess you could reproduce with any 1 channel non alpha image. But as indicated in the docs, this constructor only take RGB(A) images, thus displaying this error message.
Two solutions I would suggest : change the error message to something more explicit _and/or_ accept other type of images instead of only RGB(A) - which I have no idea of the modifications scope required to do it.
Try this:
Jimp.read({ data: src.pixels, width: src.width, height: src.height }).then((image) => { /* operation */});
src.pixels is a Buffer populated by a loop of writeUInt32BE calls.
Same issue here:
Jimp.read(fs.readFileSync('foo.png')).then(img => {
...
});
Error: No matching constructor overloading was found. Please see the docs for how to call the Jimp constructor.
I have the same problem with any image I give to this function.
ℹ REASON →
No matching constructor overloading was found. Please see the docs for how to call the Jimp constructor.
/* RESIZE OPTIMIZE IMAGES */
const Jimp = require('jimp');
/**
* Resize + optimize images.
*
* @param Object options Customizable Options.
* @param Array images An array of images paths.
* @param Number width A number value of width e.g. 1920.
* @param Number height Optional number value of height e.g. 1080.
* @param Number quality Optional number value of quality of the image e.g. 90.
*/
module.exports = async (options = {}) => {
const defaultOptions = {
images: [],
width: 1920,
height: Jimp.AUTO,
quality: 90
};
const opt = { ...defaultOptions, ...options };
await Promise.all(
opt.images.map(async imgPath => {
const image = await Jimp.read(imgPath);
await image.resize(opt.width, opt.height);
await image.quality(opt.quality);
await image.writeAsync(imgPath);
})
);
};
Turns out it was an issue with the path of the image.
Ok so i have the same issue, but the only time i get that error is when i have my image size or lower than 32x32 or higher than 90x90
Most helpful comment
I have the same problem with any image I give to this function.
ℹ REASON →
No matching constructor overloading was found. Please see the docs for how to call the Jimp constructor.