1

I want to have a border with rounded corners around an image. I also would like to have a dropped shadow effect for the image. How can I modified the answers for below question to achieve the desired effect?

Creating a drop shadow with guassian blur

I tried Tobias Holm's answer and used "rounded corners" option, but those corners are covered by the image and cannot be seen.

Here is the code I tested (path to the image needs to be changed):

\documentclass{article} 
\usepackage{tikz} % Use image shadows
\usetikzlibrary{shadows,calc}
% some parameters for customization
\def\shadowshift{3pt,-3pt}
\def\shadowradius{6pt}
\colorlet{innercolor}{black!60}
\colorlet{outercolor}{gray!05}
% this draws a shadow under a rectangle node
\newcommand\drawshadow[1]{
\begin{pgfonlayer}{shadow}
    \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)$);
    % just one change I made to use rounded corners
    \shade[outercolor,right color=innercolor,left color=innercolor, rounded corners] ($(#1.north west)+(-\shadowradius/12,\shadowradius/12)$) rectangle ($(#1.south east)+(\shadowradius/12,-\shadowradius/12)$);%Frame
    \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
\pgfdeclarelayer{shadow} 
\pgfsetlayers{shadow,main}
% Define image shadow command
\newcommand\shadowimage[2][]{%
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\drawshadow{image}
\end{tikzpicture}}

\begin{document}

\begin{figure}[tb!] \begin{tikzpicture} \node[anchor=south west,inner sep=0] (image) at (0,0) %%%%%% {\includegraphics[width=.8\linewidth]{images/ch07/DisplayGRect.jpg}}; %%%%%% \drawshadow{image}
\end{tikzpicture} \end{figure}

\end{document}

Rounded corners hidden by the image: enter image description here

Desired effect:enter image description here

Pyi Soe
  • 310
  • 1
    Please provide YOUR code, which will probably be a modification, and a screenshot … I don‘t see the corners, either for now … ;-) – MS-SPO Sep 07 '23 at 04:10
  • 1
    Added test code example and the result image. Thanks. – Pyi Soe Sep 07 '23 at 04:18
  • Ok. Just to make sure: you want your OS to open a window, and draw a gaussian shadow around it? I suggest to replace your image and pathes by something we can copy and use for a compile … unless you don‘t want answers. – MS-SPO Sep 07 '23 at 04:30
  • ? You define \shadowimage, but where do you call it? – MS-SPO Sep 07 '23 at 04:35
  • Wouldn‘t it be easier to use a graphics program, to create and save such an image? Next, it‘s a simple two-liner in Latex … – MS-SPO Sep 07 '23 at 04:37
  • I agree. But since the answers for the previous dropped shadow effect question work quite well, I was wondering if I can get my desired effect with some minor changes. If it's not that simple, I can just live with normal corners. – Pyi Soe Sep 07 '23 at 04:49
  • Well, some experienced users here will certainly find a solution. // However, what you provided so far can't complie when we copy it (please try yourself on a fresh file). We already spent 1 hour on things you could have done right in the first place while writing your question, like providing code, that will at least compile ... Even IF this place was a kind of hotline, which it clearly isn't, that's no good approach ... – MS-SPO Sep 07 '23 at 05:15
  • Sorry for the inconvenience caused. Pls don't get me wrong.I do respect this community on this StackExchange. On my machine, the code I posted do compile and produces the attached image. I guess the problem someone can't compile is this line:{\includegraphics[width=.8\linewidth]{path to my image}};. I hope any arbitary image with white background can be replaced – Pyi Soe Sep 07 '23 at 05:52
  • Just replace it in the code you post, please, and you removed just one trouble :-) – MS-SPO Sep 07 '23 at 06:06
  • BTW: to test use a new file in a new directory, i.e. disable all your internal links by intention. That's our situation far away. – MS-SPO Sep 07 '23 at 06:13

0 Answers0