jimp-dev / jimp

An image processing library written entirely in JavaScript for Node, with zero external or native dependencies.
http://jimp-dev.github.io/jimp/
MIT License
13.99k stars 760 forks source link

What is required to get Jimp supporting synchronus image loading/creating? #917

Open Lukibus opened 4 years ago

Lukibus commented 4 years ago

I would like to be able to load an image from a file (though any source would be best) and know when it was available for manipulation in a synchronous way. To know when individual manipulations have completed. My application would like to load a number of images sequentially (validating input) and then once all are validating, start processing them though separate/different/combined sequences.

Calling Jimp.load(, <WITH SOMETHING INDICATING DON'T USE PROMISES>) to return an object that can be manipulated and cloned.

Tried finding a library that doesn't require some tortuous combinations of Promises that ultimately don't work for just simply loading an image file and knowing when it has been loaded and is manipulatable.

zadam commented 4 years ago

I have similar question, but specific to buffers - there's really no reason why Jimp.load(buffer) should be async - there's no IO involved and the reading from buffer is synchronous in nature. Could there be extra API to load buffer synchronously?

willemmulder commented 4 years ago

As a workaround, the await command will wait until the Promise resolves, so then the code might look like what you want.

let jimpImage = await jimp.read(image);
// do other things