Apply multiple fadings to drawing in tikzpicture

You need to use a scope fading if you want to fade a node e.g. to include an external image. At least, so says the TikZ manual. Since your fading is not just one of the standard ones, but a bit more complex, you might want to use a picture as the basis for the fading and then apply the fading as a scope fading.

For example,

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{tikzfadingfrompicture}[name=my fading]
  \fill [transparent!0] (-2,-2) rectangle (2,2);
  \shade [left color=transparent!100, right color=transparent!0] (-3,-2) rectangle (-2,2);
  \shade [left color=transparent!0, right color=transparent!100] (2,-2) rectangle (3,2);
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
  \begin{scope}
    \path [scope fading=my fading, fit fading=false] (-3,-2) rectangle (3,2);
    \fill [color=blue] (-3,-2) rectangle (3,2);
    \node {\includegraphics{example-image}};
  \end{scope}
\end{tikzpicture}
\end{document}

faded node and stuff


One can get some partial answer using the shadows.blur package and modifying it a bit. I am using this because it already comes with the facilities to draw contours around a given shape in different steps. What one has to do is to adjust the shadow color. This has been asked here, but unfortunately I was unable to make the accepted answer work for this purpose as, according to what I find, it mocks up the steps (but I might well be doing something stupid). Yet it is not at all difficult to re-adjust the color in a TikZy way. I illustrate this by fading out a cloud because that is a fairly complicated shape, and I like the idea of making a cloud more cloudy, yet this trick can be used for general shapes.

\documentclass[tikz,border=10mm]{standalone}
\usetikzlibrary{decorations.pathreplacing,calc,shadows.blur,shapes}
% \tikzset{ % from https://tex.stackexchange.com/a/328561/121799
%     render blur shadow/.prefix code={
%       \colorlet{black}{orange}
%     }
%   } % does not work, unfortunately
\makeatletter
\tikzset{ % based on https://tex.stackexchange.com/q/328433/121799
/tikz/render blur shadow/.code={
    \pgfbs@savebb
    \pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
    \pgfbs@compute@shadow@bbox
    \pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
    \pgfbs@apply@canvas@transform
    \colorlet{pstb@shadow@color}{white!\pgfbs@opacity!\my@shadow@color}%
    \pgfdeclarefading{shadowfading}{\pgfbs@paint@fading}%
    \pgfsetfillcolor{\my@shadow@color}%
    \pgfsetfading{shadowfading}%
       {\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
    \pgfbs@usebbox{fill}%
    \pgfbs@restorebb
  },}
\tikzset{
  /tikz/shadow color/.store in=\my@shadow@color,
  /tikz/shadow color=gray,
}
\makeatother

\tikzset{
  cloudy/.style={cloud,cloud puffs=10,cloud puff arc=120, aspect=2}
}
\begin{document}
  \begin{tikzpicture}[every shadow/.style={shadow blur steps=20,
  shadow scale=1.2,shadow xshift=0pt,shadow yshift=0pt,shadow opacity=100}]
    \node[cloudy,fill=orange,blur shadow={shadow color=orange}] at (0,0) {I'm a cloud};

    \node[fill=red,blur shadow={shadow color=red,shadow scale=1.25},minimum width=4cm,minimum
    height=4cm] at (0,6){};
  \end{tikzpicture}
\end{document}

enter image description here

EDIT: Answer to edited question: Very simple, just add a white fading rectangle on top.

\documentclass[tikz,margin=5pt]{standalone}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\fill [red] (0,0) rectangle (5,5);
\node at (2.5,2.5) (Image)  {\includegraphics[width=5cm]{example-image.pdf}};
\fill [white,path fading=east] (0,0) rectangle (1,5);
\fill [white,path fading=west] (4,0) rectangle (5,5);
\draw [black] (4,0)--(4,5);
\draw [black] (1,0)--(1,5);
\draw [->,line width=1mm] (4,-0.3)--(5,-0.3);
\draw [->,line width=1mm] (1,-0.3)--(0,-0.3);
\end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf