# How can I make text automatically visible or high contrast in a Beamer presentation with photo backgrounds?

Is there an environment or package I can use to make text always visible on a beamer presentation (with photo backgrounds)? How can one ensure a 'high contrast text colour depending on the background'? (thanks @percusse)

Another way to ask this how can I make the text auto-adjust colour for optimum readability depending on it's surroundings and background?

Let's say I have a photo as a background, how can I make text pixel aware of it's surroundings and have it become lighter on the darker part of an image background and darker on the lighter parts of a background.

In instances where you have a rapid gradient (sharp or sudden white to black), the text should be outlined or some adjustment should be made to keep text readable.

An example might be pulling random photos into as frame backgrounds and not having to worry about self-adjusting and tweaking every frame for readability.

Some have suggested that content should always be the most important thing, which I understand, but that is not the issue here.

It might also be usable if the package specifies ranges so that colour adjustment can happen as in this picture:

Another example would be where we have a black to white (left to right) gradient in a picture. Layering text on this would have the text respond in the opposite gradient direction white to black (left to right). This would make the text readable regardless of where it is.

Is there a way to do this in beamer/LaTeX? Maybe the presentation and visual experts can give me a phrase or a word for what I'm looking for here.

-
No expert here but I think you are looking for high contrast text color depending on the background. However, how can one obtain the histogram of the background and select the proper color scheme in a PDF file I have no idea. Maybe branching off to Phyton or Lua before you include the background picture might help. –  percusse Jul 29 '13 at 20:51
Exactly, I was hoping something like this exists already. Question updated. –  Forkrul Assail Jul 30 '13 at 7:04
I voted to close this question since it seem impossible to solve with LaTeX … –  Tobi Nov 5 '13 at 12:49
I guess this question can’t be answered since it seems impossible with LaTeX … –  Tobi Nov 5 '13 at 12:49
@Tobi it might seem impossible. Mind if I start a bounty on it to pull in some attention? –  Forkrul Assail Nov 5 '13 at 12:50

I’d say it is impossible with LaTeX only. At least you must call some other programs in the background but even this will be to complex I guess. So prepare the images with a software like Inkscape or adobe illustrator and export the image with the text as PDF to use it in LaTeX.

-

(A little long for a comment …)

I’m not sure if this is a good idea. Assume you got several pictures with different colors, then you’ll get very different text colors on each slide and loose the connection between the slides and it won’t be e consistent design. In case of background images the effect can be even counterproductive: If the background changes from slide to slide the audience will wonder why rather than listening to you and if the background is to complex it will catch more attention that it deserves. Certainly the background can make a presentation nicer but the fore ground (i.e. text on slides, your speaking etc.) is much more important ;-)

Sure “matching colors with each picture” or “using high contrast colors” can be a design rule and work very well for some applications But I’m convinced that in this case no computer would find the really matching colors. Even if they are (mathematically) in contrast to the image, a human (designers) eye only find the colors that to the job. it’s never a good idea to let a computer do the design …

## An idea for captions on images

If you want to place a (caption) text on an image, which is not a background, I suggest to use a (white) background to all images captions. You can use TikZ To add the text, or create a new command, like \captionedimage{<caption>}[<options>]{<image>}:

\documentclass{beamer}

\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{positioning}

% define backgroundcolors
\definecolor{numberbg}{HTML}{FEF8E3}
\definecolor{numbertxt}{HTML}{C52F3E}
\definecolor{captionbg}{HTML}{FDFDF5}

% using xparse to define the new command
\NewDocumentCommand{\captionedimage}{ m O{} m }{%
\refstepcounter{figure}
\begin{tikzpicture}
% include the image in a node
\node (graphic) [inner sep=0pt] {\includegraphics[#2]{#3}};
% draw the node for the number
\node (number) [%
below right=1mm of graphic.north west,
fill=numberbg,
text=numbertxt,
font=\Large\bfseries,
minimum width=3em,
minimum height=5.4ex] {\thefigure};
% draw the node with the caption
\node [%
right=-0.5pt of number.north east,
anchor=north west,
fill=captionbg,
text width=12em,
font=\footnotesize,
minimum height=5.4ex] {#1};
\end{tikzpicture}
}

\begin{document}
\title{Captioned images}
\maketitle
\begin{frame}
\captionedimage{Caption Text}[width=\textwidth]{example-image}
\end{frame}
\begin{frame}
\captionedimage
{A very long caption Text. A very long caption Text.}
[width=\textwidth]{example-image-a}
\end{frame}
\begin{frame}
\captionedimage{Caption Text}[width=\textwidth]{example-image-b}
\end{frame}
\end{document}


I just borrowed the color theme of TeX.SX, but it would be much better to define the colors according to the beamer color theme …

-
Thanks for the extended answer and example @Tobi, I've learned quite a few new things here. I don't know either if this is a good design idea or not, but have seen it more frequently in a lot of online and industry presentations. The idea however is to not deviate too far from existing slides - to be able to use old/existing slides (standard frames, that would just have high contrast text depending on the background), just with more interesting backgrounds (maybe more 'punchy' for students?). –  Forkrul Assail Jul 30 '13 at 17:57
@ForkrulAssail: I extended my answer a little, and I claim that it’s is impossible to get satisfying results with an automatic computer based approach. Maybe you can show more examples, but I’m sure that they are hand-made … –  Tobi Jul 30 '13 at 19:27
thanks again for your attempt, yet this doesn't solve my problem. The whole point would be not to have a caption area but 1) have the text colour be adjusted (by the character if need be), 2) have this happen automatically depending on the background image's locational colour. –  Forkrul Assail Nov 5 '13 at 12:42
I know, but I’d say it is impossible to do it in TeX. Tex isn’t an image processor ;-) So if you want to use TeX you must use another solution for example the on I posted as an answer or you must use another software … –  Tobi Nov 5 '13 at 12:47