# Crop jpeg into circular tikz node

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

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}


Image is writelatex's frog.jpg

• ooh dat frog! :) – Paulo Cereda Jul 28 '14 at 13:27
• I see a latex-memes package incoming. – Ingo Jul 29 '14 at 7:02
• Perfect choice of example picture and text. – Raphael Jul 29 '14 at 15:50
• This approach requires me to put some text inside the circle to make it visible. How can I get the full size image without any text? – nimcap Feb 16 '18 at 7:35
• @nimcap set the minimum width, minimum heigth or minimum size keys to enlarge the node without text – percusse Feb 16 '18 at 7:37

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}


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

\documentclass[border=5mm]{standalone}
\usepackage[skins]{tcolorbox}
\begin{document}
\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}


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

\documentclass[border=5mm]{standalone}
\usepackage[skins]{tcolorbox}
\begin{document}
\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}


• The tcolorbox package is amazing. Thanks a lot! – Hansimov Aug 22 '18 at 9:35

Since I could not find writelatex's frog.jpg, I'm using the Masked tree frog head from Charlesjsharp on Wikimedia, which is 851x567 px big.

I like to use clip, since one can then clip the image with lots of different shapes. In this case I clip the image with a circle of half the radius of the shorter length of the image, centered onto the middle of the image.

\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);
\end{tikzpicture}

\end{document}


• Is there any way to enable anti-aliasing on this solution? – Unapiedra Jul 29 '14 at 11:56
• @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 '14 at 13:24
• You have a lot of seemingly magic numbers. I'd like to see this with more documentation or an explanation of those numbers. – jvriesem Jan 5 '16 at 21:59
• @jvriesem The numbers are not magic at all. The image I used is 851x567 px big. I'm centering the circle with a radius of half of the smaller length on the middle of the image (851/2 and 567/2), The \imsize of 0.618 is 1/phi, from the Golden ratio, which would not be necessary for this example where only the image is shown and there's no text to relate the image width to. – Habi Jan 6 '16 at 9:52

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}


• Note that the small circles are not drawn on the top but they clip the image with even-odd rule. – kiss my armpit Jul 28 '14 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 '14 at 15:21
• @Fran: I took a mutant of the frog. :-) – kiss my armpit Jul 29 '14 at 16:03