// assumes bgColor is a rgb() string: "rgb(66, 134, 244)" function getTextColor(c) { let rgb = c.substring(4, bgColor.indexOf(')')).split(", ").map(x => parseInt(x)); let o = Math.round(((parseInt(rgb[0]) * 299) + (parseInt(rgb[1]) * 587) + (parseInt(rgb[2]) * 114)) /1000); return ((o > 125) ? ('black') : ('white')); }
So this returns black or white, but what if the ideal solution returned, perhaps a very dark version of the background color. Like, dark blue on light blue might be more pleasant than black on light blue etc.
Would this work then? get color, convert color to HSL, return L - 100 % 100
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So this returns black or white, but what if the ideal solution returned, perhaps a very dark version of the background color. Like, dark blue on light blue might be more pleasant than black on light blue etc.
Would this work then? get color, convert color to HSL, return L - 100 % 100