# Creating a drop shadow with guassian blur

How can I add a drop shadow to a \includegraphics picture? The effect should be very minute just to be a little bit eye pleasing. I know you can use \shadowbox in fancybox package but the output would not be like this.

Sample:

Created with the drop shadow effect in Inkscape.

-
This might help: Faded drop-shadow using tikz-based rounded rectangle?.. –  Werner Nov 7 '12 at 20:26
Here's a link to another drop-shadow question (that led to a package on CTAN): tex.stackexchange.com/q/50422/86 –  Andrew Stacey Nov 7 '12 at 23:38

One possibility is to use Caramdir's answer to Faded drop-shadow using tikz-based rounded rectangle?) (all credit goes to Caramdir).

Using the \drawshadow command form the linked answer, I defined a \shadowpicture command with one optional argument (the options that will be passed to the optional argument of \includegraphics), and a mandatory argument (the name of the file containing the image). Using \colorlet one can change the values for innercolor and outercolor, controlling the values used for the shadow.

Using the xparse package one can easily define \shadowpicture to have three optional arguments (the two colors and the optional values for \includegraphics) and a mandatory one (the name of the image file).

\documentclass{article}
\usepackage{tikz}

% some parameters for customization

\colorlet{innercolor}{black!60}
\colorlet{outercolor}{gray!05}

% this draws a shadow under a rectangle node
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
\shade[top color=innercolor,bottom color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
\shade[left color=innercolor,right color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
\shade[bottom color=innercolor,top color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
\shade[outercolor,right color=innercolor,left color=outercolor] ($(#1.south west)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
\filldraw ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)-(\shadowradius/2,\shadowradius/2)$);
\end{pgfonlayer}
}

% create a shadow layer, so that we don't need to worry about overdrawing other things

\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\end{tikzpicture}}

\begin{document}

\end{document}

A little improvement: now the shadow size adjusts automatically depending proportionally on the image size:

\documentclass{article}
\usepackage{tikz}

% some parameters for customization

\colorlet{innercolor}{black!60}
\colorlet{outercolor}{gray!05}

% this draws a shadow under a rectangle node
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
\shade[top color=innercolor,bottom color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
\shade[left color=innercolor,right color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
\shade[bottom color=innercolor,top color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
\shade[outercolor,right color=innercolor,left color=outercolor] ($(#1.south west)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
\filldraw ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)-(\shadowradius/2,\shadowradius/2)$);
\end{pgfonlayer}
}

% create a shadow layer, so that we don't need to worry about overdrawing other things

\newsavebox\mybox
\newlength\mylen

\setbox0=\hbox{\includegraphics[#1]{#2}}
\setlength\mylen{\wd0}
\ifnum\mylen<\ht0
\setlength\mylen{\ht0}
\fi
\divide \mylen by 120
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\end{tikzpicture}}

\begin{document}

\end{document}

-
I suspect that these are fungi that are responsible for the blurring effect and not the LaTeX code. :-) –  projetmbc Nov 7 '12 at 22:36
Whatever you do with this image looks fantastic. –  percusse Nov 7 '12 at 22:39
Perfect! The macro \shadowimage is wonderful. I wished I could vote up +10 :) –  rowman Nov 8 '12 at 8:01
Could you do one more improvement? Suppose the total size of the image should not change at all. So \includegraphics image should be downscaled abit. What is the total width which is added by shadow? radius + shift? –  rowman Nov 30 '12 at 16:54
@rowman I think I don't understand your comment; you want to change the width of the shadow but I don't understand in which way. Could you please elaborate a little more? –  Gonzalo Medina Nov 30 '12 at 17:36