Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\documentclass[demo]{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[circle,draw,inner sep=2cm]{\includegraphics{myimage.jpg}};
\end{tikzpicture}
\end{document}

How do I modify the above code so that the included image is adapted to the circle shape and cropped of the exceeding parts?

I want to specify a shape (a circle) and then include an image respecting the given dimension and cropped.

share|improve this question

4 Answers 4

up vote 32 down vote accepted

You can use path picture key.

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\tikz\node[circle,draw,
           text=white,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=3.5cm]{frog}
               };
           }]{I'm watching you!};
\end{document}

enter image description here

Image is writelatex's frog.jpg

share|improve this answer
    
ooh dat frog! :) –  Paulo Cereda Jul 28 at 13:27
4  
I see a latex-memes package incoming. –  Ingo Jul 29 at 7:02
1  
Perfect choice of example picture and text. –  Raphael Jul 29 at 15:50

Here is another frog solution which also uses path picture beneath. If you don't mind loading tcolorbox for this purpose, you can use its fill overzoom image option for TikZ. This option takes a picture file name as parameter (here frog.jpg again) and scales this image to fit into (or better: over) the shape:

\documentclass[border=5mm]{standalone}
\usepackage[skins]{tcolorbox}
\begin{document}
\begin{tikzpicture}
  % one picture
  \node[circle,draw,inner sep=2cm,fill overzoom image=frog] (A) {};

  % some more
  \foreach \w in {1,2,...,6}
  {
    \path (A) (\the\numexpr\w*60\relax:\the\numexpr 3+\w/2\relax cm)
      node[circle,draw,inner sep=\the\numexpr\w*2\relax mm,fill overzoom image=frog] (B) {};
    \draw[very thick,red,->] (A)--(B);
  }
\end{tikzpicture}
\end{document}

enter image description here

As a bonus, here are some more frogs put into different shapes (zoomed automatically):

\documentclass[border=5mm]{standalone}
\usepackage[skins]{tcolorbox}
\begin{document}
\begin{tikzpicture}[radius=1cm,delta angle=180]
\path[draw,thick,fill overzoom image=frog]
  (0,0) arc [start angle=-90] -- ++(-2,0) arc [start angle=90] -- cycle;
\path[draw,thick,fill overzoom image=frog]
  (3.5,2) arc [start angle=0] -- ++(0,-2) arc [start angle=180] -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

And, finally, just one frog which fills a path consisting of two separate parts:

\documentclass[border=5mm]{standalone}
\usepackage[skins]{tcolorbox}
\begin{document}
\begin{tikzpicture}[radius=1cm,delta angle=180]
\path[draw,thick,fill overzoom image=frog]
  (0,4) arc [start angle=-90] -- ++(-2,0) arc [start angle=90] -- cycle
  (3.5,6) arc [start angle=0] -- ++(0,-2) arc [start angle=180] -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

Since I could not find writelatex's frog.jpg, I'm using the Masked tree frog head from Charlesjsharp on Wikimedia...

I like the approach of using clip, since one can then clip the image with lots of different shapes...

\documentclass{article}

\usepackage{graphicx}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}  
\PreviewEnvironment{tikzpicture}

\newcommand{\imsize}{\linewidth}
\newlength\imagewidth
\newlength\imagescale

\begin{document}

\renewcommand{\imsize}{0.618\linewidth}
\pgfmathsetlength{\imagewidth}{\textwidth}%
\pgfmathsetlength{\imagescale}{\imagewidth/851}%

\begin{tikzpicture}[x=\imagescale,y=-\imagescale]
    \clip (851/2, 567/2) circle (567/2);
    \node[anchor=north west, inner sep=0pt, outer sep=0pt] at (0,0) {\includegraphics[width=\imagewidth]{Masked_tree_frog_head}};
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Is there any way to enable anti-aliasing on this solution? –  Unapiedra Jul 29 at 11:56
1  
@Unapiedra: Tha anti-aliasing is most probably an artefact from the conversion from pdf to (tiny) jpg. The original file is cropped by a neat circle, as you can see in this screenshot showing the zoomed in document. –  Habi Jul 29 at 13:24

A bit enhanced circular clipper with PSTricks.

\documentclass[pstricks,border=12pt,dvipsnames]{standalone}
\usepackage{graphicx}
\usepackage{multido}
\newsavebox\IBox
%\savebox\IBox{\includegraphics[scale=3]{example-grid-100x100pt}}
\savebox\IBox{\includegraphics[width=6cm]{golum}}

\def\HColumns{10} %half columns
\def\HRows{10} %half rows

\psset
{
    xunit=0.5\dimexpr\wd\IBox/\HColumns,
    yunit=0.5\dimexpr\ht\IBox/\HRows,
    runit=\psxunit,
}

\begin{document}
\begin{pspicture}[showgrid=false](-\HColumns,-\HRows)(\HColumns,\HRows)
    \psline[linecolor=red,linewidth=12pt](-\HColumns,-\HRows)(\HColumns,\HRows)
    \psclip
    {
        \pscustom[linestyle=none,linewidth=0]
        {
            \code{ /clip /eoclip load def }
            \multido{\n=2+2}{5}{\pscircle(0,0){\n}}
        }
    }
    \rput(0,0){\usebox\IBox}
    \endpsclip
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
2  
Note that the small circles are not drawn on the top but they clip the image with even-odd rule. –  stalking is prohibited Jul 28 at 17:26
    
Do not know why, but I imagine that you were not gonna take the tender frog and sample image. –  Fran Jul 29 at 15:21
1  
@Fran: I took a mutant of the frog. :-) –  stalking is prohibited Jul 29 at 16:03

Your Answer

 
discard

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.