TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a rectangular image that I can not change.

I'd like to clip the image with a bezier path so I get one that is rectangular at the top and the sides but has a curve at the bottom, preferable without using additional packages.

share|improve this question
No package needed if you clip the image using an image editor in advance. As far as I know, graphicx can only clip images in a rectangular form. Therefore you need additional packages such as PSTricks to clip it in a curved form. – xport Jun 5 '11 at 12:15
Using an editor in advance is not an option, unfortunatelly. Additional packages are acceptable (thou a solution without them would be preferable). – Richard Durr Jun 5 '11 at 12:17
Your image in what format? eps, jpeg, png, or pdf? – xport Jun 5 '11 at 12:24
can be converted during the compile-process. let us assume it is png. – Richard Durr Jun 5 '11 at 13:10
Herbert's solution that is compiled by xelatex can import png, pdf, jpg, eps. – xport Jun 5 '11 at 13:13
up vote 17 down vote accepted

I don't know of a way to clip an image without using additional packages (apart from graphicx, I assume). There is a way of doing it with TikZ, which is probably better than no solution.

This is based on the answers to the question Drawing on an image with TikZ. I've written a macro that takes an image name with the accompanying \includegraphics options and a TikZ path as arguments to either display the image overlaid with a grid and the path, or to use the path to clip the image. The behaviour is toggled using \tikzset{develop clipping path=true} to switch on the grid and the path display, and \tikzset{develop clipping path=false} to perform the actual clipping once the path has been developed.



    \tikzset{/tikz/develop clipping path/.is if=developpath,
      /tikz/develop clipping path=true}

    % Include the image to determine the size and set up the relative coordinate system. Enclose the \includegraphics in \phantom{} once the clipping path has been set up
      \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics#1};
      \node[anchor=south west,inner sep=0] (image) at (0,0) {\phantom{\includegraphics#1}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
      % Draw grid while developing clipping path
        \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
        \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
        \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
        \draw[red, ultra thick] #2 -- cycle;
        % Use the path to clip, include the image
        \path[clip] #2 -- cycle;
        \node[anchor=south west,inner sep=0pt] {\includegraphics#1};

Show the image with a grid to help in finding the coordinates for the path.

    \clippicture{[width=0.8\textwidth]{some-image}}{(0.5,0.75) -- (0.90,0.75) -- (0.90,0.5) .. controls (0.8,-0.2) and (0.65,0.2) .. (0.5,0.3)}

    \tikzset{develop clipping path=false}
Done with developing the path. Do the actual clipping.

    \clippicture{[width=0.8\textwidth]{some-image}}{(0.5,0.75) -- (0.90,0.75) -- (0.90,0.5) .. controls (0.8,-0.2) and (0.65,0.2) .. (0.5,0.3)}

clipping an image with a bezier

share|improve this answer
Cool, thanks! :) – Richard Durr Jun 5 '11 at 13:15

run with xelatex, then a pdf image can be clipped





enter image description here

share|improve this answer
It is a compact solution with a nice photograph. – xport Jun 5 '11 at 13:09
I'll evaluate this solution, too! Thanks! :) – Richard Durr Jun 5 '11 at 13:15
You can use \pst@boxg as a temporary box. – xport Jun 22 '11 at 7:39
@xport: I know, but it requires makeatletter ....\makeatother and it is defined for internal use of PSTricks – Herbert Jun 22 '11 at 7:45

I take some ideas from Drawing on an image with Tikz but with another method and I complete the code with Jack's method for the clip image.


\tikzset{number/.style={fixed,fixed zerofill,precision=1}} 
\tikzset{spy style/.style={spy using outlines={magnification=8, size=4cm}}}
\begin{scope}[spy style] 
\node[anchor=south west,inner sep=0](GHimage){\includegraphics[width=#1]{#2}}; 
\begin{scope}[x={(GHimage.south east)},y={(GHimage.north west)}]}{% 

\node[anchor=south west,inner sep=0](GHimage){\phantom{\includegraphics[width=#1]{#2}}}; 
\begin{scope}[x={(GHimage.south east)},y={(GHimage.north west)}]}{% 

width/.code                    = \def\GH@width{#1},
height/.code                   = \def\GH@height{#1}, 
/GHShowDetail/.unknown/.code   = {\let\searchname=\pgfkeyscurrentname

\def\GH@ShowDetail[#1] at (#2,#3)#4{
         width   = 0.1,
         height  = 0.1}
    \path (#2,#3)--++(\GH@width/2,\GH@height/2) coordinate (rightnode)
          (#2,#3)--++(-\GH@width/2,-\GH@height/2) coordinate (leftnode);
    \node [fit=(leftnode) (rightnode),
           ultra thick,draw,
           color= lightgray,
           ](#4)  {};}

/GHShowPath/.unknown/.code   = {\let\searchname=\pgfkeyscurrentname

        \draw[#1] #2 -- cycle; 

\clip  #2 -- cycle;
\node[anchor    = south west,
      inner sep = 0](GHimage){%

color/.code         = \def\GH@anchor@col{#1},
radius/.code        = \def\GH@anchor@rad{#1},
show/.is if         = anchor@show,
show/.default       = true}

\def\GH@Anchor[#1] at (#2,#3)#4{%
color  = gray,
radius = 2pt,
show   = false}  
\coordinate (#4) at (#2,#3);
\ifanchor@show\fill[\GH@anchor@col] (#4) circle [radius=\GH@anchor@rad];\fi

color/.code         = \def\GH@grid@col{#1},
space/.code         = \def\GH@grid@space{#1},
step/.code          = \def\GH@grid@step{#1},
precision/.code     = \def\GH@grid@precision{#1}, 

color  = lightgray,
space = 0.04,
precision = 1}
\foreach \x in {0,\GH@grid@step,...,1.001}{%
    \draw[\GH@grid@col] (0,\x) ++(-\GH@grid@space,0) node[left]{%
    \pgfmathprintnumber[fixed,fixed zerofill,precision=\GH@grid@precision]
                       {\x}} -- (1,\x);
    \draw[\GH@grid@col] (\x,0) ++(0,-\GH@grid@space)node[rotate=90,left]{%
    \pgfmathprintnumber[fixed,fixed zerofill,precision=\GH@grid@precision]
                       {\x}} -- (\x,1);}}

color/.code         = \def\GH@anchor@col{#1},

  \spy  on (#1) in node at ([shift={(#3,#4)}]GHimage.#2); 


\tikzset{spy style/.style={spy using outlines={circle, magnification=4, size=3cm, connect spies}}}

   \GHAnchor[color=red,radius=2pt,show] at (0.5,0.5){milieu}   
   \GHShowDetail[shape=circle,color=red,width=.2] at (0.25,0.5){cercle}
   \GHShowDetail[shape=rectangle,width=.1,height=.1] at (0.7,0.7){rec}
   \GHShowPath[ultra thick,red]{(0.5,0.75) -- (0.90,0.75) -- (0.90,0.5) .. controls (0.8,-0.2) and (0.65,0.2) .. (0.5,0.3)} 

\GHShowClipPath[red]{(0.5,0.75) -- (0.90,0.75) -- 
    (0.90,0.5) .. controls (0.8,-0.2) and (0.65,0.2) .. (0.5,0.3)} 

enter image description here

share|improve this answer

I am not using Bezier. It is just for fun.




        \psparametricplot{0}{2.5 .25 exp}{t^2  | 0.8*(sqrt(2.5-t^4)+t)}
        \psparametricplot{2.5 .25 exp}{0}{t^2  | 0.8*(-sqrt(2.5-t^4)+t)}
        \psparametricplot{0}{2.5 .25 exp}{-t^2 | 0.8*(-sqrt(2.5-t^4)+t)}
        \psparametricplot{2.5 .25 exp}{0}{-t^2 | 0.8*(sqrt(2.5-t^4)+t)}


    \pscustom[unit=2.3cm, origin={0.5\width,0.4\height}, linecolor=cyan, dimen=middle, linewidth=3pt, algebraic]{\function}
    \psgrid[gridwidth=0.2pt, gridcolor=white, subgriddiv=1]

    \psclip{\pscustom[unit=2.3cm, origin={0.5\width,0.4\height}, linestyle=none, algebraic]{\function}}
    \psgrid[gridwidth=0.2pt, gridcolor=white, subgriddiv=1]

enter image description here

share|improve this answer

This is a clipper with bezier curves.

enter image description here

\documentclass[pstricks,border={-8.5mm -5.5mm -8.5mm -5.0mm}]{standalone}


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

        (!Minor Major theta p2c){I}
        (!Minor Major theta neg p2c){J}

    \psellipticarcn[dimen=middle](center)(!Major Minor){(I)}{(J)}

    \psellipticarcn[dimen=middle](center)(!Major Minor){(J')}{(I')}


%    \DeclareNodes
%    \pscustom*{\RightPart\LeftPart\closepath}




Another similar method can be seen here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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