Open
Description
Expected Behavior
When using Jimp.read()
, decoder options, e.g.
Jimp.read(buffer, { 'image/jpeg': { maxMemoryUsageInMB: 2048 } }))
are passed to the decoder when decoding an image from a Buffer or a file.
Current Behavior
Decoder options are not passed to the underlying decoder, unless the first argument in Jimp.read(url, options)
is a URL. This leads to, e.g., the inability to decode large JPEGs due to memory errors, since maxMemoryUsageInMB
cannot be set.
Failure Information (for bugs)
I suspect the issue is that the read()
method returns this.fromBuffer(...)
instead of this.fromBuffer(..., options)
unless the first argument is a URL.
static async read(
url: string | Buffer | ArrayBuffer,
options?: MimeTypeToDecodeOptions
) {
if (Buffer.isBuffer(url) || url instanceof ArrayBuffer) {
return this.fromBuffer(url); // <--------------------------------- here
}
if (existsSync(url)) {
return this.fromBuffer(await readFile(url)); // <---------------------- here
}
const [fetchErr, response] = await to(fetch(url));
if (fetchErr) {
throw new Error(`Could not load Buffer from URL: ${url}`);
}
if (!response.ok) {
throw new Error(`HTTP Status ${response.status} for url ${url}`);
}
const [arrayBufferErr, data] = await to(response.arrayBuffer());
if (arrayBufferErr) {
throw new Error(`Could not load Buffer from ${url}`);
}
const buffer = bufferFromArrayBuffer(data);
return this.fromBuffer(buffer, options); // <---------------------- but here returns correctly
}
Context
- Jimp Version: 1.6.0
- Operating System: Windows 10
- Node version: 22.11.0
Metadata
Metadata
Assignees
Labels
No labels