lwip
lwip copied to clipboard
Invert colors
trafficstars
How to invert colors of an image? I have a flat black icon and I want to turn it white: I've tried also image.lighten(1) with no success.
I could loop with getPixel/setPixel, but I'm worried about the performance and the setPixel callback management. Maybe with a sync version of setPixel it will be easier.
Here's what I am using now. It's slow but at least I can achieve what I need.
require('async').timesSeries(image.width(), function(x, x_next) {
require('async').timesSeries(image.height(), function(y, y_next) {
var pixel = image.getPixel(x, y);
pixel.r = 255 - pixel.r;
pixel.g = 255 - pixel.g;
pixel.b = 255 - pixel.b;
image.setPixel(x, y, pixel, y_next);
}, x_next);
});
Hey, maybe this would be the type of thing to ask on Stack Overflow instead?