无法在 bookcover 中使用 pgfshade

无法在 bookcover 中使用 pgfshade

我正在使用优秀的\shadowimage经过贡萨洛·梅迪纳创建带有阴影的图像。

此外,我还使用该bookcover包创建书籍封面:

\documentclass{bookcover}

\input{shadowimage} % code from Gonzalo's answer

\begin{document}
\begin{bookcover}
    \shadowimage{bunnies.png}
\end{bookcover}
\end{document}

不幸的是,如果我像这样\shadowimage包装:\bookcovercomponent

\documentclass{bookcover}

\input{shadowimage} % code from Gonzalo's answer

\begin{document}
\begin{bookcover}
    \bookcovercomponent{normal}{front}{
       \shadowimage{bunnies.png}}
\end{bookcover}
\end{document}

阴影不起作用,并且我收到以下警告:

xdvipdfmx:warning: Error locating image file "pgfshade17"
xdvipdfmx:warning: Specified (image) object doesn't exist: pgfshade17
xdvipdfmx:warning: Interpreting special command uxobj (pdf:) failed.
xdvipdfmx:warning: >> at page="1" position="(491.233, 376.719)" (in PDF)
xdvipdfmx:warning: >> xxx "pdf:uxobj @pgfshade17"
xdvipdfmx:warning: Error locating image file "pgfshade17"
...
xdvipdfmx:warning: Error locating image file "pgfshade19"
xdvipdfmx:warning: Specified (image) object doesn't exist: pgfshade19
xdvipdfmx:warning: Interpreting special command uxobj (pdf:) failed.
xdvipdfmx:warning: >> at page="1" position="(491.233, 376.719)" (in PDF)
xdvipdfmx:warning: >> xxx "pdf:uxobj @pgfshade19"

我能做些什么来修复它吗?

答案1

很难看出错误可能来自哪里,因为shadowimage.tex您并不清楚加载的内容是什么。但是,对我来说,Gonzalo 的代码和使用的代码版本都shadows.blur运行良好。这是 Gonzalo 版本。

\documentclass{bookcover}
\usetikzlibrary{shadows,calc}

% code adapted from https://tex.stackexchange.com/a/11483/3954

% 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)$);
        \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}

\newsavebox\mybox
\newlength\mylen

\newcommand\shadowimage[2][]{%
\setbox0=\hbox{\includegraphics[#1]{#2}}
\setlength\mylen{\wd0}
\ifnum\mylen<\ht0
\setlength\mylen{\ht0}
\fi
\divide \mylen by 120
\def\shadowshift{\mylen,-\mylen}
\def\shadowradius{\the\dimexpr\mylen+\mylen+\mylen\relax}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\drawshadow{image}
\end{tikzpicture}}

\newsavebox\Bunnies
\sbox\Bunnies{\shadowimage{bunnies.png}}
\begin{document}
\begin{bookcover}    
    \usebox{\Bunnies}
\end{bookcover}
\end{document}

和这里shadows.blur

\documentclass{bookcover}
\usetikzlibrary{shadows.blur}
\sbox\Bunnies{\tikz{\node[blur shadow]{\includegraphics{bunnies.png}};}}
\begin{document}
\begin{bookcover}    
    \usebox{\Bunnies}
\end{bookcover}
\end{document}

相关内容