0

I want to draw text on an Image in the inverse color of the background (to make sure the text is readable no matter the background color).

This is what it should look like:

enter image description here


Related:

HappyFace
  • 3,439
  • 2
  • 24
  • 43
  • Keep in mind that the inverse color of `#7f7f7f` is `#808080`, which is essentially indistinguishable. – Mario Welzig Mar 14 '21 at 20:55
  • @MarioWelzig IK, this is a practical matter used with reasonable images. – HappyFace Mar 14 '21 at 20:56
  • What is the "inverse" of a color? Is it an RGB color? What if the background is an image (and not a single color)? – martineau Mar 14 '21 at 20:58
  • Might be of interest [How to draw text with image in background?](https://stackoverflow.com/questions/50297272/how-to-draw-text-with-image-in-background) – martineau Mar 14 '21 at 20:59
  • @martineau The inverse needs to be calculated per pixel (each background pixel has a single color which has an inverse). – HappyFace Mar 14 '21 at 21:00
  • You still haven't defined what the inverse of a color is. – martineau Mar 14 '21 at 21:01
  • I don't understand. Get the colour of the background, subtract it from 255 and draw your text that colour. Which part are you stuck with? – Mark Setchell Mar 14 '21 at 21:02
  • @martineau I think the inverse should an XOR of the background color with white, but I know the inverse effect from Photoshop etc, so I am not sure. – HappyFace Mar 14 '21 at 21:21
  • @MarkSetchell The background is a picture, not a single solid color. – HappyFace Mar 14 '21 at 21:22
  • Maybe it would be clearer if you edited your question to show what you are looking for if you can mock it up in Photoshop. – Mark Setchell Mar 14 '21 at 21:24
  • Draw the text in white on a black background same size as original. Get the coordinates of the white pixels. Invert pixels at those coordinates in original image. Maybe. Untested. – Mark Setchell Mar 14 '21 at 21:30
  • @MarkSetchell That was my idea as well. Won't anti-aliasing and stuff be a problem? I guess it shouldn't matter much ... – HappyFace Mar 14 '21 at 21:42
  • I don't know yet. You haven't given any indication of the content, size or type of your image, nor what style/font/size of text you plan to use, nor how you expect the result to look. – Mark Setchell Mar 14 '21 at 21:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229910/discussion-between-happyface-and-mark-setchell). – HappyFace Mar 14 '21 at 21:49
  • Also, if that was your best idea, you should have shown that as your best attempt at code in your question. – Mark Setchell Mar 14 '21 at 21:49
  • @PeterO. Yes. I have linked to it as an answer, actually. – HappyFace Mar 14 '21 at 23:55

0 Answers0