function getYiq ( rgb ) { return ( rgb [ 0 ] * 299 + rgb [ 1 ] * 587 + rgb [ 2 ] * 114 ) / 1000 ; } function bodyTextColor ( rgb ) { return getYiq ( rgb ) < 150 ? "#fff" : "#000" ; } function titleTextColor ( rgb ) { return getYiq ( rgb ) < 200 ? "#fff" : "#000" ; } function createPixelArray ( imgData , quality = 10 ) { const pixels = imgData . data ; const pixelCount = imgData . shape [ 0 ] * imgData . shape [ 1 ] ; const pixelArray = [ ] ; for ( let i = 0 , offset , r , g , b , a ; i < pixelCount ; i = i + quality ) { offset = i * 4 ; r = pixels [ offset + 0 ] ; g = pixels [ offset + 1 ] ; b = pixels [ offset + 2 ] ; a = pixels [ offset + 3 ] ; if ( typeof a === 'undefined' || a >= 125 ) { if ( ! ( r > 250 && g > 250 && b > 250 ) ) { pixelArray . push ( [ r , g , b ] ) ; } } } return pixelArray ; } export { getYiq , bodyTextColor , titleTextColor , createPixelArray } ;