I want to include an image. However, to make it blend in a little better, I'd like to add (overlay) a faded border that doesn't exist in the figure at the moment.
My attempt is to use transparent
and a regular, thick-edge \fbox
:
\documentclass{article}
\usepackage{transparent,graphicx,xcolor}
\begin{document}
\noindent
{\setlength{\fboxsep}{-10pt}%
\setlength{\fboxrule}{10pt}% Rule will overlay with image
\transparent{0.8}\color{white}% Rule is 50% white/transparent
\fbox{%
\includegraphics[width=100pt]{example-image}}%
}
\end{document}
This lacks serious pizazz. How can I do this using some transparency with a graphics package (or modify the \fbox
construction to make it work)? Can I make the blend-in be gradual?
Best Answer
Here is an attempt with TikZ, using the
calc
andfadings
libraries. The code is heavily inspired by some drop-shadow work done by Caramdir at Faded drop-shadow using tikz-based rounded rectangle?I defined a command
\framenode
, which accepts one optional and one mandatory argument:where
<frame-radius>
is the radius of the fade around the rectangle, as a dimension (default10pt
), and<node>
is the name of the node to frame.The command only works on rectangular nodes. For the example, I've placed an image in a node called
image
withinner sep=0
so the node tightly fits the image dimensions. Then I useto frame the node
image
with a fade of radius15pt
.Update: It turns out I made my life much harder than it needed to be. Much simplified code is posted now. The radial shading and clipping were both unnecessary because of the way
pgf
handles "pixel painting" when transparency is involved. There is a slight difference in the corners, but I don't think it's overly significant. It also avoids the viewer aliasing problems inherent in the first version.Complete Code:
Before (complex code)
After (simplified code)