18

I've recently seen this the following image in this question:

enter image description here

As I was looking for a way to create nice captions (without the "Figure:") for a beamer presentation, I wondered if it was possible to create this effect within LaTeX.

I got so far with GIMP:

enter image description here enter image description here

I did it like this:

  1. add a white layer where the caption will go and set it's transparancy to 50%
  2. gaussian blur on the image where the caption will go 3 add the caption

Can I do this within LaTeX, too?

I have a couple of images which I would like to include in a beamer presentation like this, so it would be great if this worked.

(I've tried a google image search for this, but "latex caption" seems not to be good ... even when I filter explicit results)

My try:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{tikz}

\begin{document}
\begin{preview}
    \begin{tikzpicture}
        \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\linewidth]{foto-martin.jpg}};
        \begin{scope}[x={(image.south east)},y={(image.north west)}]
            \draw[white, fill=white!50!transparent] (0,0.05) rectangle (1,0.1);
            \node at (0.5, 0.075) {\Huge Martin};
        \end{scope}
    \end{tikzpicture}
\end{preview}
\end{document}

But I don't know how to get the transparency / positioning working.

As somebody suggested imagemagick, I tried this:

width=`identify -format %w foto-martin.jpg`;     convert         -background '#0008'         -fill white         -gravity center         -size ${width}x40             caption:"Martin"             foto-martin.jpg +swap         -gravity south         -geometry +0+10        -composite  out.jpg

But I can't get some padding for the text in the caption and the box arround.

Martin Thoma
  • 18,799
  • I'd bet that a tikz-based solution is going to appear here within 30 minutes;). (Would do it myself if I had time now.) Edit: though the blur would be a problem. – mbork Mar 06 '13 at 18:36
  • Idea II: \write18 and ImageMagick. – mbork Mar 06 '13 at 18:38
  • @mbork: I'm working on it, I don't know how to make this half-transparent overlay and the positioning – Martin Thoma Mar 06 '13 at 18:41
  • Idea III: I guess that even the blur is doable (though inefficiently) with tikz - just clip the right part of the translation of the picture a few times and put it with suitable opacity settings. Though I'd go with ImageMagick and either \write18 or a Makefile (or arara, or whatever like that). – mbork Mar 06 '13 at 18:44
  • see chapter 20 of tikz manual, this might help. – mbork Mar 06 '13 at 18:45
  • 6
  • 1
    @cmhughes: Thank you very much! The positioning-problem is now almost fixed :-) – Martin Thoma Mar 06 '13 at 19:00
  • @cmhughes: good point, I forgot about that question - but the blur is the hard part here, I guess;). (And transparency, to much lesser degree.) – mbork Mar 06 '13 at 19:00
  • 2
    @moose Writing your name on your forehead is the equivalent of putting a caption inside a picture:-) I wouldn't recommend it. –  Mar 06 '13 at 19:13
  • 2
    @MarcvanDongen: OTOH, you might want to put some text on a (blurred) part of the picture and make it semi-transparent, so I find the question more general-purpose and very good indeed. One application that comes to mind is a calendar on a photograph. (I did something like that in Gimp, with pictures of my daughter for my parents, and it was an instant hit;).) – mbork Mar 06 '13 at 19:21
  • 3
    @MarcvanDongen I have to do a presentation about a project. This includes showing five team members. I would like to do it on one slide. This means, I don't have much space for captions below. Additionally, I think this looks very good. – Martin Thoma Mar 06 '13 at 20:00

2 Answers2

14

Assuming that this question isn't a duplicate of Drawing on an image with TikZ you can achieve what you want by using the opacity=<value> key, where value can be anything between 0 (invisible) and 1 (completely visible).

screenshot

Complete MWE

\documentclass{beamer}

\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\linewidth]{mushroom}};
        \begin{scope}[x={(image.south east)},y={(image.north west)}]
            \draw[white, fill=gray,opacity=0.5] (0,0) rectangle (1,0.15);
            \node[opacity=0.5] at (0.5, 0.075) {\Huge Mushroom};
        \end{scope}
    \end{tikzpicture}
\end{document}
cmhughes
  • 100,947
12

Here's an approach that uses ImageMagick to blur the image and place a clipped version on top of the unblurred image (which requires -shell-escape or -enable-write18 to call the external program). The whole thing is wrapped in a macro called \labelimage{<file name>}{<image width>}{<label text>}. The background rectangle style can be set using image label background/.style, the label node uses image label text/.style:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\tikzset{
    image label text/.style={
        white, font=\sffamily
    },
    image label background/.style={
        white, opacity=0.35
    }
}
\newcommand{\labelimage}[3]{
    \begin{tikzpicture}
        \immediate\write18{convert #1 -blur 0x3 blurred#1}
        \node [inner sep=0pt] (original) {\includegraphics[#2]{#1}};
        \begin{scope}[
            fill=white,
            shift=(original.south west),
            x=(original.south east),
            y=(original.north west)
        ]
        \fill [clip] (0,0.05) rectangle (1,0.25);
            \node [inner sep=0pt, anchor=south west] {\includegraphics[#2]{blurred#1}};
            \fill [image label background] (0,0.05) rectangle (1,0.25)
                node [text opacity=1, pos=0.5, image label text] {#3};
        \end{scope}
    \end{tikzpicture}
}
\labelimage{martin.jpg}{width=4em}{Martin}

\end{document}
Jake
  • 232,450
  • 1
    +1. Your solution requires -shell-escape or -enable-write18... – Paul Gaborit Mar 06 '13 at 22:50
  • Could you adjust your solution so that I can resize the image? I would like to call it like \labelimage[width=0.3\textwidth,height=0.4\textheight,keepaspectratio]{foto-martin.jpg}{Martin}. I've also noticed that relative paths like ../images/foto-peter.jpg seem not to work. – Martin Thoma Mar 06 '13 at 22:51