1

This post is an extension of How to Crop an Image Precisely in the Shape of a Norman Window

Consider the code which embeds an image of a Norman Window inside a pspicture:

\documentclass{book}
\usepackage{tikz,pstricks,xcolor,graphicx}


% Compile with Xelatex

\newsavebox\IBox
\savebox\IBox{\includegraphics[width=12em,height=15em]{example-image}}

\begin{document}
\thispagestyle{empty}
\begin{pspicture}(-4,-4)(4,8)%
\psframe[fillcolor=red,fillstyle=solid](-4,-4)(4,8)
\rput(0,2.5){\begin{tikzpicture}
\clip (0,0) -- (\wd\IBox,0) -- (\wd\IBox, \ht\IBox-0.5*\wd\IBox)
arc[start angle=0, end angle=180, radius={0.5\wd\IBox}] -- cycle;
\node[inner sep=0pt, above right] at (0,0) {\usebox\IBox};
\end{tikzpicture}}
\end{pspicture}%
\end{document}

which produces the image

enter image description here

QUESTION: Compiling the code with Xelatex, how may I colorize the Norman Window, say, blue?

Thank you.

2 Answers 2

2
\documentclass[border=12pt]{standalone}
\usepackage{pstricks}

\begin{document}
%\psset{unit=2}
\begin{pspicture}[showgrid=true](-3,-3)(9,9)
\psframe*[linecolor=blue](-3,-3)(9,9)
\psclip{%
  \pscustom[linestyle=none,dimen=middle]{%
    \psline(6,0)(6,3)
    \psarc(3,3){3}{0}{180}
    \psline(0,0)
  }}
\psframe*[linecolor=red](-3,-3)(9,9)
\endpsclip
\end{pspicture}
\end{document}

enter image description here

Instead of clipping you can use a simple \pscustom.

3

Natural steps:

  • Put the image on the bottom layer
  • Put the window frame on the top

The most important concept is in the window frame. The transparent region is due to even-odd rule.

The pspicture* removes the part of image outside the canvas.

enter image description here

\documentclass[pstricks,border=1cm]{standalone}
\usepackage{graphicx}
\newbox\IBox
\savebox\IBox{\includegraphics[scale=1]{example-image-a}}

\begin{document}
\begin{pspicture*}[showgrid=t](-2,-2)(2,4)
\rput(0,0){\usebox\IBox}
\end{pspicture*}

\begin{pspicture*}[showgrid=t](-2,-2)(2,4)
\pscustom[dimen=m,linejoin=2,fillstyle=solid,fillcolor=red]{%
    \psline(2,4)(2,-2)(-2,-2)(-2,4)\closepath% clockwise
    \psarc[liftpen=2](0,2){1}{0}{180}\psline(-1,2)(-1,-1)(1,-1)(1,2)\closepath% counter-clockwise
}
\end{pspicture*}

\begin{pspicture*}[showgrid=t](-2,-2)(2,4)
\rput(0,0){\usebox\IBox}
\pscustom[dimen=m,linejoin=2,fillstyle=solid,fillcolor=red]{%
    \psline(2,4)(2,-2)(-2,-2)(-2,4)\closepath% clockwise
    \psarc[liftpen=2](0,2){1}{0}{180}\psline(-1,2)(-1,-1)(1,-1)(1,2)\closepath% counter-clockwise
}
\end{pspicture*}
\end{document}

Note: The last pspicture* might be the output you want to use. The other ones are intentionally added just for creating the animation. So you need to remove the first two pspicture* and showgrid=t in your production.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.