Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
6  
Drawing on an image with TikZ –  cmhughes Mar 6 '13 at 18:53
1  
@cmhughes: Thank you very much! The positioning-problem is now almost fixed :-) –  moose Mar 6 '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. –  Marc van Dongen Mar 6 '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 6 '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. –  moose Mar 6 '13 at 20:00
show 6 more comments

2 Answers 2

up vote 14 down vote accepted

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}
share|improve this answer
    
Arrgh.... I wait a little the delete mine eheh. That mushroom is magic! –  percusse Mar 6 '13 at 22:18
    
There is no blurred effect! –  Paul Gaborit Mar 6 '13 at 22:22
    
@cmhughes: I didn't know opacity=0.5. Thank you! –  moose Mar 6 '13 at 22:53
    
I've adjusted some values a little bit. May I edit your solution? As I applied your solution to my presentation, I noticed that I have to choose the adjust the font size manually. Not that was a big problem ... Here is the result –  moose Mar 6 '13 at 22:56
    
I'd like to give +2 because from all the captions in this thread so far, this one looks the most beautiful, blur effect or not. –  Christian Mar 7 '13 at 1:29
add comment

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}
share|improve this answer
1  
+1. Your solution requires -shell-escape or -enable-write18... –  Paul Gaborit Mar 6 '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-mar‌​tin.jpg}{Martin}. I've also noticed that relative paths like ../images/foto-peter.jpg seem not to work. –  moose Mar 6 '13 at 22:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.