get image contrast

node v8.12.0
version: 1.0.0
endpointsharetweet
const lwip = require('lwip'); const request = require('request'); const chroma = require('chroma-js'); const imgUrl = 'https://prismic-io.s3.amazonaws.com/latoex-portal/8fca37f71580b6233692c44da01d8e62fac1f88b_services-andes-trading-system.png'; request({ url: imgUrl, encoding: null }, (error, response, buffer) => { lwip.open(buffer, 'png', (err, image) => { const width = image.width(); const height = image.height(); let count = 0; while ( i <= width && j <= height ) { const { r, g, b } = image.getPixel(i, j); } for(let i = 0; i <= width; i += 5) { for(let j = 0; j <= width; j += 5) { } } const color = chroma([r, g, b]); const lum = color.luminance(); console.log(color.hex(), lum > 0.4 ? '#000' : '#fff' ); }); // console.log({ body }); }); null;
Loading…

no comments

    sign in to comment