I'd suggest a shadow/outline for most practical uses.
For one thing, you are calculating the average of the whole image.
But imagine if most of the image is white, while exactly where the text goes is a black rectangle?
Then you have to calculate that exact position.
But what if that area is striped?
's "hacky" CSS solutions will probably be more performant AND more effective, being able to invert the image color with the text.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.