EyalAr / lwip

Light Weight Image Processor for NodeJS
MIT License
2.36k stars 231 forks source link

Provide a way to loop over and process each pixel in the image. #141

Open zlsa opened 9 years ago

zlsa commented 9 years ago

The way it would be called:

var img = lwip.open("image.png");
img.foreach(function process(color) { return "black"; },
            function done(err, img) {
              ...
            });

It should be functionally identical to a loop with getPixel() and setPixel() but could be optimized in the future. I may try and add this myself if I have the time.

abritinthebay commented 8 years ago

Obviously this is possible with the toBuffer code but a cleaner API would be nice. That said - the API above is a bit limited.

I'd suggest image.eachPixel(callback(err, pixel));

Where the pixel param is an object with xpos, ypos, and color in it. Then returning a color object (as defined in the libaray) would overwrite the data and returning undefined would be the same as rgba(0,0,0,0) or a pass-through... depending on what you want the api to be.

Promise support is obviously nice.