Hacker News new | ask | show | jobs
by andrewvc 4656 days ago
This is a nice step, but not good enough for practical use. Put the text half on the black lamp, half off, and you get 1/2 invisible text. While interesting, it's not reliably accurate enough to use in any sort of automated fashion.
6 comments

In graphics design I usually pick the colour that contrasts most with the background, and use a text-shadow (looks better than an outline, anyway) in the other colour. Use none or very little shadow blur.

What you should most definitely not do, is give each character (or word) its own colour depending on the background. As others pointed out, this would be a pain to implement, wrapping everything in spans etc, but most importantly it also just looks terrible.

Though the very first step is to simply try and see if you can avoid the situation entirely :) [which may be harder if the images are user supplied]

I disagree although my first thought was exactly the same; how do you solve the problem of half of some text being on a dark background and the other half on a lighter area.

I see three solutions to the problem.

The first is not so elegant. If you have text then you wrap each letter in a span tag and apply the JS to each span. Very ugly, not practical, scalable, etc. but it works. If you've got dynamic text coming from a backend then just forget it. This solution is only viable for static content and even then it's not great.

You could implement this as instructed and then just give the text an outline of the exact opposite color. Chances are your text will not equally overlap both a light and dark background so this wouldn't look too bad at all.

The third solution is to just know your backgrounds very well and choose element placement very carefully so that no matter what background you have your text ends up in an all light or all dark part of it. If I had Medium style app where users get to choose the background image of an element that gets text laid over it this is what I might be okay with doing and accepting that not all the background images will lend themselves well to this technique.

Or... There's a fourth way that I've actually had to consider in one of my projects. Until I saw this post I didn't have the final piece of the puzzle but now I do. I would take the ability to dynamically change the text color based on a background and add to it a translucent background to the text with some padding to make it a blocky thing - kind of like how ios7 handles it in notification center.

The idea is that if you have an element over a mostly light background you give that text itself a light background with about 70% - 80% opacity and the text color dark. This way you're covered even if part of the text is on top of some random dark part of the image background. It's the same idea as using a text outline except its more cross-browser compatible and I personally think it looks better.

But like I said, if you're not in control of the text and/or background there probably isn't going to be a bullet proof solution and you'll have to accept trade offs but if you are in total control then there's no reason you can't mitigate these issues completely.

A reasonable solution to this might be to determine when the number of pixels that'd match dark v light is near the midpoint, adding a text-shadow (for text) or box-shadow (everything else) of 1px with the more dominant of the two colors.

Edit: Looked closer at the library, if he just added dark-mid or light-mid styles when close, the user can implement the appropriate visual differentiator. Should be good.

If it implemented some requirements of your choosing with perfect accuracy, how would you go about automating any work other than flipping colors to contrast with background?

I'm not in the graphics design business, but I could only imagine applying that tool manually, in an interactive see-if-it's good environment much like the demonstration.

It'd useful for overlaying things on maps, or tagged things in photos etc.

For designers it's not very useful of course.

did you try half text in white panel and half in the third? it turns BLUE!! Ingenious. So they got the right direction, but they have to fix the sensing on that because yes, it still has trouble with the lamp
Another issue I see is that it doesn't take into account any of the elements which are already in position. Placing the small circle over the large circle hides it.