1

I'm using the excellent \shadowimage by Gonzalo Medina to create an image with a drop shadow.

In addition, I'm using the bookcover package to create a book cover:

\documentclass{bookcover}

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

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

Unfortunately, if I wrap \shadowimage in \bookcovercomponent like so:

\documentclass{bookcover}

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

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

the shading doesn't work, and I get the following warnings:

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"

Is there anything I can do to fix it?

1 Answers1

5

It is hard to see where an error may come from since it is not really clear what is in shadowimage.tex which you load. However, for me both Gonzalo's code and a version using shadows.blur work fine. Here's the Gonzalo version.

\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}

and here 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}
  • Thanks for the answer, I'll check it a bit later, but I've updated my question with the "bad" example which shows the error. Using \bookcovercomponent is the crucial part. Thanks! – Igal Tabachnik Aug 13 '18 at 11:06
  • @IgalTabachnik For this, you only need to replace \usebox{\Bunnies} by \bookcovercomponent{normal}{front}{\usebox{\Bunnies}}. Note also that there is a warning Package textpos Warning: environment textblock* not in vertical mode. but I think it is unrelated to the issue you are fighting with. –  Aug 13 '18 at 11:32
  • 1
    Thanks, I was finally able to make it work with shadows.blur after adding \newbox\Bunnies right before the \sbox... command. Thanks again! – Igal Tabachnik Aug 13 '18 at 19:53