4

Consider the code

\documentclass{book}
\usepackage{graphicx}
\usepackage[abs]{overpic}
\usepackage{tikz}
\definecolor{Gold}{RGB}{228,168,73}

\begin{document} \thispagestyle{empty} \begin{center} \begin{tikzpicture} \clip (0,0) ellipse (4.25cm and 5.5cm); \node at (0,0) {\includegraphics[scale=2]{example-image-a}}; \end{tikzpicture} \end{center} \end{document}

which produces the cropped image:

enter image description here

QUESTION: How may I add a gold border (of a specified thickness) around the oval-shaped cropped image? I am using xelatex to compile.

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36

3 Answers3

3

This code will draw the frame inside the node.

Notice that half the width of the line is lost in the clip.

\documentclass{book}
\usepackage{graphicx}
\usepackage[abs]{overpic}
\usepackage{tikz}
\definecolor{Gold}{RGB}{228,168,73}

\begin{document} \thispagestyle{empty} \begin{center} \begin{tikzpicture} \clip (0,0) ellipse (4.25cm and 5.5cm); \node at (0,0) {\includegraphics[scale=2]{example-image-a}}; \draw[line width=10pt, Gold] ellipse (4.25cm and 5.5cm); % added <<<<<<<<<< \end{tikzpicture} \end{center} \end{document}

a

Simon Dispa
  • 39,141
1

To avoid clipping of the golden contour, the scope of the clipping path can be limited using the scope environment. This prevent parts of the clipped object from extending beyond the overlaid contour (caused by numerical imprecision of the PDF viewer / image conversion tool).

Also, the clipping path can be defined once and re-used elsewhere using save path and use path options:

\documentclass{book}
\usepackage{graphicx}
\usepackage[abs]{overpic}
\usepackage{tikz}
\definecolor{Gold}{RGB}{228,168,73}

\begin{document} \thispagestyle{empty} \begin{center} \begin{tikzpicture} \begin{scope} \clip[save path=\myContour] (0,0) ellipse (4.25cm and 5.5cm); \node at (0,0) {\includegraphics[scale=2]{example-image-a}}; \end{scope} \draw[line width=5pt, Gold,use path=\myContour]; \end{tikzpicture} \end{center} \end{document}

AlexG
  • 54,894
1

This is what the path picture is made for. With it you can put arbitrary TikZ stuff inside the path, the area that would be filled by the fill color, by a pattern or a shading.

I'm also using the low-level \pgftext here to avoid the inner node to inherit any other options from its parent path (for example, that node would also have a Gold drawn border, though we don't see that because it gets clipped).

In the previous link I also mention the tikzfill package which gives a few predefined options for placing a picture inside a path.

Code

\documentclass{book}
\usepackage{tikz}
\definecolor{Gold}{RGB}{228,168,73}

\begin{document} \thispagestyle{empty} \begin{center} \begin{tikzpicture} \draw[Gold, ultra thick] (0,0) ellipse (4.25cm and 5.5cm) [path picture={ \pgftext[at=\pgfpointanchor{path picture bounding box}{center}] {\includegraphics[scale=2]{example-image-a}} % \node at (path picture bounding box.center) % {\includegraphics[scale=2]{example-image-a}}; }]; \end{tikzpicture} \end{center} \end{document}

Qrrbrbirlbel
  • 119,821