Cutting an image to get rounded corners

The previous recipe gave us an edged image. It can be nice to have rounded corners, so let us take a look at how to achieve that.

How to do it...

We will use a few features of the very capable tikz graphics package:

  1. Load the tikz package in your preamble:
    \usepackage{tikz}
  2. Declare a box for storing the image:
    \newsavebox{\picbox}
  3. Define a macro that allows us to use our recipe repeatedly:
    \newcommand{\cutpic}[3]{
      \savebox{\picbox}{\includegraphics[width=#2]{#3}}
      \tikz\node [draw, rounded corners=#1, line width=4pt,
        color=white, minimum width=\wd\picbox,
        minimum height=\ht\picbox, path picture={
          \node at (path picture bounding box.center) {
            \usebox{\picbox}};
        }] {};}
  4. Use the new macro within your document to include ...

Get LaTeX Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.