23

I am trying to create a fancy image by clipping an external image by an ellipse- the area inside the ellipse will be shown only. I have seen this, but I still need help. Can anybody help?

Here's an instance of what I am saying:

img

hola
  • 4,026
  • 3
  • 35
  • 72
  • 3
    Section 15.5 of the pgfmanual is about this topic and gives an explicit example on how to do that. Does this help? – Bordaigorl Jan 19 '14 at 16:34
  • 3
    Here's a precise link: http://mirror.ox.ac.uk/sites/ctan.org/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf#165 – Bordaigorl Jan 19 '14 at 16:40

2 Answers2

27

With TikZ

Code

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usepackage{mwe} % provides example-image-a
\begin{document}
\begin{tikzpicture}
    \clip(0,0)circle[x radius=4cm, y radius=2cm];
    \node{\includegraphics{example-image-a}};   
\end{tikzpicture}
\end{document}

Output

enter image description here

Herr K.
  • 17,946
  • 4
  • 61
  • 118
16

With PSTricks just for fun.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=1]{example-grid-100x100pt}}
\psset
{
    xunit=.1\wd\IBox,
    yunit=.1\ht\IBox,
}
\begin{document}
\begin{pspicture}(10,10)
    \psclip{\psellipse(5,5)(5,4)}
    \rput(5,5){\usebox\IBox}
    \endpsclip
\end{pspicture}
\end{document}

enter image description here

Bonus

An elliptical batman clipping path.

\documentclass[pstricks,border=0pt]{standalone}
\SpecialCoor
\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=1]{example-grid-100x100pt}}
\psset
{
    xunit=\dimexpr\wd\IBox/14,
    yunit=\dimexpr\ht\IBox/14,
}

% b a t p2c ---> x y
% where b (semi-minor), a (semi-major), t (theta)
\pstVerb{/p2c {dup 3 1 roll cos mul 3 1 roll sin mul} bind def}


\def\RightPart
{
    \psline(0.5,2.7)(1,3.25)
    \psbezier(1.2,1.3)(1.3,1.0)(2.0,1.0)
    \psbezier(3.0,1.0)(3.0,2.2)(!3.3 6.0 72 p2c)
    \psellipticarcn(6.0,3.3){(!3.3 6.0 72 p2c)}{(!3.3 6.0 72 neg p2c)}
    \psbezier(4,-2)(4,0)(2.2,-1.8)
    \psbezier(1.5,-1)(1,-1)(0,-3.2)
}


\begin{document}

\begin{pspicture}(-7,-4)(7,4)
\psclip{
    \pscustom[dimen=monkey]
    {
    \RightPart
    \reversepath
    \scale{-1 1}
    \RightPart
    \closepath
    }}
    \rput(0,0){\usebox\IBox}
\endpsclip
\end{pspicture}
\end{document}

enter image description here