I'm trying to get the average color (rgba) of a single arbitrary character in Javascript. I'm aware this may produce different results on different setups; that's fine and expected behavior. How can this be done?
Asked
Active
Viewed 52 times
-2
-
1What do you mean, "the average colour of a character"? – Blackhole Nov 19 '19 at 20:46
-
I mean literally "what's the average color of the pixels that make up the x-y dimensions that the character takes up" – GameKyuubi Nov 19 '19 at 22:45
1 Answers
-2
You might be thinking about how browsers interpret a string value of the bgColor
property like a color by splitting the string into three hex values. Which is why element.bgColor = "chucknorris"
changes the element's background colour to RGB(192, 0, 0).
See the below answer for more examples and a description of why it happens.

stewartmcgown
- 516
- 4
- 16
-
-
I am not thinking of this. I mean literally how do I figure out the average color of an arbitrary character chosen at random, like "A" or "" – GameKyuubi Nov 19 '19 at 22:47
-
no need for a downvote though! You could have phrased your question a bit better. You'll need to choose a font to inspect in order to get the average colour. Characters are not stored as 'pixel-maps' inside JavaScript. – stewartmcgown Nov 19 '19 at 23:16
-
I'm not the one who downvoted you! Though I can see why you would think that, I would assume the same :) I can give you a second and then remove it later to prove it if you like lol – GameKyuubi Nov 19 '19 at 23:53
-