模糊的演出背景

模糊的演出背景

我正在尝试为每个图形创建一个框架。类似于这个 - 带有模糊阴影的纯白色圆角矩形。

阴影

这可以用乳胶完成吗?你能告诉我怎么做吗?

答案1

这是一个快速解决方案。它可以变得更加可定制,可能是为了合并pgfkeys键值选项。

代码

\documentclass[parskip,a5paper]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main}

\newcommand{\myshadow}[5]% file name, scale, color, max color, decrease
{   \begin{tikzpicture}
        \node[rounded corners=3mm,inner sep=3mm,draw,fill=white] (temppicnode) {\includegraphics[scale=#2]{#1}};
        \begin{pgfonlayer}{background}
            \foreach \x in {1,...,10}
            {   \pgfmathsetmacro{\mycolor}{#4-#5*(\x-1)}
                \fill[rounded corners=3mm,#3!\mycolor] ($(temppicnode.south west)+(-0.5+\x/20,-0.5+\x/20)$) rectangle ($(temppicnode.north east)+(0.5-\x/20,0.5-\x/20)$);
            }
        \end{pgfonlayer}
    \end{tikzpicture}
}

\begin{document}
    \begin{figure}
        \myshadow{book.png}{1}{gray}{40}{4}
    \end{figure}
    \begin{figure}
        \myshadow{book.png}{1}{red}{100}{10}
    \end{figure}
        \begin{figure}
        \myshadow{book.png}{1}{blue}{50}{2}
    \end{figure}
\end{document}

输出

在此处输入图片描述


编辑1:哦,你想要的是逆渐变。以下是两种变体,还有更多内容可以根据你的喜好进行调整:

代码

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\newcommand{\myborder}[8]% file name, scale, color, max color, decrease
{   \begin{tikzpicture}
        \node[rounded corners=#7 cm,inner sep=#7 cm,fill=white] (temppicnode) {\includegraphics[scale=#2]{#1}};
        \begin{pgfonlayer}{background}
            \foreach \x [evaluate=\x] in {1,...,#8}
            {   \pgfmathsetmacro{\mycolor}{#4 -(#4-#5)/#8*(\x-1)}
                \pgfmathsetmacro{\mycorners}{#6 +#7 -\x*#6/#8}
                \fill[rounded corners=\mycorners cm,#3!\mycolor] ($(temppicnode.south west)+(-#6+\x*#6/#8,-#6+\x*#6/#8)$) rectangle ($(temppicnode.north east)+(#6-\x*#6/#8,#6-\x*#6/#8)$);
            }
        \end{pgfonlayer}
    \end{tikzpicture}
}

\newcommand{\myshadow}[8]% file name, scale, color, max color, min color, width, inner radius, steps
{   \begin{tikzpicture}
        \node[rounded corners=#7 cm, inner sep=#7 cm, fill=white] (temppicnode) {\includegraphics[scale=#2]{#1}};
        \begin{pgfonlayer}{background}
            \foreach \x [evaluate=\x] in {1,...,#8}
            {   \pgfmathsetmacro{\mycolor}{#5+(#4-#5)/#8*(\x-1)}
                \pgfmathsetmacro{\mycorners}{#6+ #7 -\x*#6/#8}
                \fill[rounded corners=\mycorners cm,#3!\mycolor] ($(temppicnode.south west)+(-#6+\x*#6/#8,-#6+\x*#6/#8)$) rectangle ($(temppicnode.north east)+(#6-\x*#6/#8,#6-\x*#6/#8)$);
            }
        \end{pgfonlayer}
    \end{tikzpicture}
}

\begin{document}
    \myshadow{book.png}{1}{gray}{80}{5}{0.5}{0.3}{10}
    \myshadow{book.png}{1}{gray}{80}{5}{0.5}{0.3}{50}
    \myborder{book.png}{1}{gray}{80}{5}{0.5}{0.3}{10}
    \myborder{book.png}{1}{gray}{80}{5}{0.5}{0.3}{50}

    \myshadow{book.png}{1}{red}{40}{5}{0.3}{0.1}{10}
    \myshadow{book.png}{1}{red}{40}{5}{0.3}{0.1}{50}
    \myborder{book.png}{1}{blue}{20}{2}{0.3}{0.1}{10}
    \myborder{book.png}{1}{blue}{20}{2}{0.3}{0.1}{50}
\end{document}

输出

在此处输入图片描述


编辑2:修复了边框宽度计算的问题:

代码

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\newcommand{\myborder}[8]% file name, scale, color, max color, decrease
{   \begin{tikzpicture}
        \node[rounded corners=#7 cm,inner sep=#7 cm,fill=white] (temppicnode) {\includegraphics[scale=#2]{#1}};
        \begin{pgfonlayer}{background}
            \foreach \x [evaluate=\x] in {1,...,#8}
            {   \pgfmathsetmacro{\mycolor}{#4 -(#4-#5)/#8*(\x-1)}
                \pgfmathsetmacro{\mycorners}{#6 +#7 -(\x-1)*#6/(#8-1)}
                \fill[rounded corners=\mycorners cm,#3!\mycolor] ($(temppicnode.south west)+(-\mycorners+#7,-\mycorners+#7)$) rectangle ($(temppicnode.north east)+(\mycorners-#7,\mycorners-#7)$);
            }
        \end{pgfonlayer}
    \end{tikzpicture}
}

\newcommand{\myshadow}[8]% file name, scale, color, max color, min color, width, inner radius, steps
{   \begin{tikzpicture}
        \node[rounded corners=#7 cm, inner sep=#7 cm, fill=white] (temppicnode) {\includegraphics[scale=#2]{#1}};
        \begin{pgfonlayer}{background}
            \foreach \x [evaluate=\x] in {1,...,#8}
            {   \pgfmathsetmacro{\mycolor}{#5+(#4-#5)/#8*(\x-1)}
                \pgfmathsetmacro{\mycorners}{#6+ #7 -(\x-1)*#6/(#8-1)}
                                \fill[rounded corners=\mycorners cm,#3!\mycolor] ($(temppicnode.south west)+(-\mycorners+#7,-\mycorners+#7)$) rectangle ($(temppicnode.north east)+(\mycorners-#7,\mycorners-#7)$);
            }
        \end{pgfonlayer}
    \end{tikzpicture}
}

\begin{document}
    \myshadow{book.png}{1}{gray}{80}{5}{0.5}{0.3}{10}
    \myshadow{book.png}{1}{gray}{80}{5}{0.5}{0.3}{50}
    \myborder{book.png}{1}{gray}{50}{2}{0.5}{0.3}{10}
    \myborder{book.png}{1}{gray}{50}{2}{0.5}{0.3}{50}

    \myshadow{book.png}{1}{red}{40}{5}{0.3}{0.1}{10}
    \myshadow{book.png}{1}{red}{40}{5}{0.3}{0.1}{50}
    \myborder{book.png}{1}{blue}{20}{2}{0.3}{0.1}{10}
    \myborder{book.png}{1}{blue}{20}{2}{0.3}{0.1}{50}
\end{document}

输出

在此处输入图片描述

相关内容