lwip icon indicating copy to clipboard operation
lwip copied to clipboard

Invert colors

Open lorenzos opened this issue 9 years ago • 2 comments
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.

lorenzos avatar Jan 12 '16 17:01 lorenzos

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);
});

lorenzos avatar Jan 12 '16 20:01 lorenzos

Hey, maybe this would be the type of thing to ask on Stack Overflow instead?

alanhogan avatar Mar 30 '16 01:03 alanhogan