Polaroid photo effect in tikz
Edit (2016/05/27): Improved version at the end -- cleaner box style, usage of xparse
.
Something like this
Description: I defined a command \polaroid
, taking five arguments, the first being optional, designed for the tcolorbox
only.
- 1st arg:
tcolorbox
settings - 2nd arg: Rotation angle in degrees
- 3rd arg: Scaling of the image
- 4th arg: Image file name
- 5th arg: Caption
The shadow is blurred now, the detailed settings depend on the personal request and can not be done here, change the fuzzy shadow
option values at will.
\documentclass[paper=a4,12pt]{article}%
\usepackage{tcolorbox}%
\usepackage{etoolbox}%
\tcbuselibrary{skins}%
\begin{document}%
\newcommand{\polaroid}[5][top=1cm,left=1cm,right=1cm,bottom=1cm,boxsep=0pt,colback=white,width=8cm,arc=0pt,auto outer arc,fuzzy shadow={2mm}{-2mm}{1mm}{0.3mm}{black}]{%
\tcbset{enhanced}
\rotatebox{#2}{%
\begin{tcolorbox}[#1]
\begin{center}%
\setlength{\fboxrule}{0.2pt}%
\setlength{\fboxsep}{0pt}%
\fbox{%
\includegraphics[scale=#3]{#4}}
#5%
\end{center}%
\end{tcolorbox}%
}%
}%
\polaroid{-10}{0.25}{face}{\Large \textsf{\textbf{Hello World!}}}%
\end{document}
Old version
\documentclass[paper=a4,12pt]{scrartcl}
\usepackage{tcolorbox}%
\usepackage{etoolbox}%
\begin{document}%
\rotatebox{10}{\begin{tcolorbox}[width=8cm]%[shadow={2mm}{-1mm}{0mm}{black!50!white}]
\begin{center}
\includegraphics[scale=0.5]{bild_erwin_schroedinger}
\Huge Hello World%
\end{center}
\end{tcolorbox}
}%
\end{document}
About the jaggy lines issue: Adding a tight \fbox
around the image overprints the lines, but it is only a work around.
Admitted, Erwin Schrödinger is not as sexy as that actress ;-)
Update A better version, with tikz
styles and special settings:
Another version of the \polaroid
command, this time with xparse
:
- 1st arg optional:
tcolorbox
settings - 2nd arg: file name
- 3rd arg optional : Scaling of the image
- 4th arg: caption
- 5th arg optional : rotation angle
\documentclass[12pt]{article}%
\usepackage[most]{tcolorbox}%
\tcbset{%
polaroid/.style={%
enhanced,
top=1cm,
left=1cm,
right=1cm,
bottom=1cm,
boxsep=0pt,
colback=white,
width=8cm,
sharp corners,
lower separated=false,
halign=center,
valign=center,
halign lower=center,
fuzzy shadow={2mm}{-2mm}{1mm}{0.3mm}{black}
},%
polaroidframe/.style={%
size=tight,
boxrule=2pt,
colframe=black,
}%
}
\newtcolorbox{polaroidbox}[1][]{%
polaroid,
#1
}
\newtcbox{polaroidframe}[1][]{%
polaroidframe,
#1
}
\NewDocumentCommand{\polaroid}{O{}mO{0.25}+mO{-10}}{%
\rotatebox{#5}{%
\begin{polaroidbox}[#1]
\polaroidframe{\includegraphics[scale=#3]{#2}}
\tcblower
#4
\end{polaroidbox}%
}
}
\begin{document}%
\polaroid{face}[0.2]{\Large\bfseries \sffamily Hello World}[180]
\polaroid{face}[0.2]{\Large\bfseries \sffamily Hello World}[0]
\polaroid{face}[0.2]{\Large\bfseries \sffamily Hello World}[90]
\polaroid{face}[0.2]{\Large\bfseries \sffamily Hello World}[270]
\end{document}
Here is a flexible and customizable solution usable into a tikzpicture.
Description of keys:
at
defines the center of the picture,graphics options
defines the options used by\includegraphics
,rotate
defines the global rotation of the polaroid,caption
define the content of the caption,caption distance
defines the distance between the top of caption and the bottom of the picture,top margin
,bottom margin
,left margin
,right margin
,vmargin
,hmargin
andmargin
are used to define the margins between the picture and the borders of the polaroid,caption option
defines the options used by the caption node,frame options
defines the options used by the frame node (the whole polaroid).
Each key has a default value. The optional argument of \polaroid
macro is used to change these value for a particular polaroid. You may use \polaroidset
to change the default values for all subsequent polaroids in the current group.
\documentclass[tikz]{standalone}%
\usetikzlibrary{fit,calc,shadows,backgrounds,positioning}
\tikzset{
polaroid/.cd,
at/.store in=\polaroidat,
at={0,0},
graphics options/.store in=\polaroidgraphicsoptions,
graphics options=,
rotate/.store in=\polaroidrotate,
rotate=0,
caption/.store in=\polaroidcaption,
caption=,
caption distance/.store in=\polaroidcaptiondistance,
caption distance=1mm,
top margin/.store in=\polaroidtopmargin,
bottom margin/.store in=\polaroidbottommargin,
left margin/.store in=\polaroidleftmargin,
right margin/.store in=\polaroidrightmargin,
vmargin/.style={top margin=#1,bottom margin=#1},
hmargin/.style={left margin=#1,right margin=#1},
margin/.style={vmargin=#1,hmargin=#1},
margin=1cm,
caption default/.style={font=\bfseries,node distance=1mm},
caption options/.style={caption default/.append style={#1}},
frame default/.style={draw,inner sep=0},
frame options/.style={frame default/.append style={#1}},
}
\newcommand\polaroidset[1]{\tikzset{polaroid/.cd,#1}}
\newcommand\polaroid[2][]{
\bgroup
\tikzset{polaroid/.cd,#1}
\pgfmathsetmacro\polaroidrotate{\polaroidrotate}
\begin{scope}[shift={(\polaroidat)},rotate=\polaroidrotate]
\node[rotate=\polaroidrotate,inner sep=0]
(shoot) {\expandafter\includegraphics\expandafter[\polaroidgraphicsoptions]{#2}};
\path (shoot.north) ++(0,\polaroidtopmargin) coordinate (polaroid top);
\path (shoot.south) ++(0,{-1*(\polaroidbottommargin)}) coordinate (polaroid bottom);
\path (shoot.west) ++({-1*(\polaroidleftmargin)},0) coordinate (polaroid left);
\path (shoot.east) ++(\polaroidrightmargin,0) coordinate (polaroid right);
\node[rotate fit=\polaroidrotate,fit=(polaroid top)(polaroid bottom)(polaroid left)(polaroid right),polaroid/frame default]{};
\node[rotate=\polaroidrotate,inner sep=0]
(shoot) {\expandafter\includegraphics\expandafter[\polaroidgraphicsoptions]{#2}};
\coordinate (caption center) at ($(shoot.south)!-1 * \polaroidcaptiondistance!(shoot.north)$);
\node[anchor=north,rotate=\polaroidrotate,polaroid/caption default]
(caption) at (caption center) {\polaroidcaption};
\end{scope}
\egroup
}
\begin{document}%
\begin{tikzpicture}
\polaroid[rotate=-10,
frame options={line width=1pt,draw,rounded corners=.5mm,fill=white,drop shadow},
graphics options={width=4cm}]
{face}
\end{tikzpicture}
\begin{tikzpicture}
\polaroidset{
rotate=20,
frame options={line width=1pt,draw=cyan,rounded corners=.5mm,fill=cyan!10,drop shadow},
graphics options={width=2.5cm},
caption options={font=\footnotesize,align=center},
caption distance=.5mm,
vmargin=5mm,hmargin=5mm,
bottom margin=5mm+1em,
}
\foreach \i in {0,...,6}{
\polaroid[rotate={90-\i*30},at={{90-\i*30+90}:5cm},caption=Hello\\World]{face}
}
\end{tikzpicture}
\end{document}
Based on https://tex.stackexchange.com/a/180442/36296
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{backgrounds, calc, shadows, shadows.blur}
\newcommand\addcurlyshadow[2][]{
% #1: Optional aditional tikz options
% #2: Name of the node to "decorate"
\begin{pgfonlayer}{background}
\rotatebox{10}{%
\path[blur shadow={shadow xshift=0pt, shadow yshift=0pt, shadow blur steps=6}, #1]
($(#2.north west)+(.3ex,-.5ex)$)
-- ($(#2.south west)+(.5ex,-.7ex)$)
.. controls ($(#2.south)!.3!(#2.south west)$) .. (#2.south)
.. controls ($(#2.south)!.3!(#2.south east)$) .. ($(#2.south east)+(-.5ex,-.7ex)$)
-- ($(#2.north east)+(-.3ex, -.5ex)$)
-- cycle;
}
\end{pgfonlayer}
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\rotatebox{10}{%
\node[draw=black!40, fill=white, rectangle, minimum width=4.5cm, minimum height=4.5cm]
(example) {
\setlength{\fboxrule}{0.2pt}%
\setlength{\fboxsep}{0pt}%
\fbox{%
\includegraphics{example-grid-100x100bp.pdf}%
}%
};
\addcurlyshadow{example}
}
\end{tikzpicture}
\end{frame}
\end{document}