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:
Load the
tikz
package in your preamble:\usepackage{tikz}
Declare a box for storing the image:
\newsavebox{\picbox}
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}}; }] {};}
Use the new macro within your document to include an image:
\cutpic{1cm}{8cm}{filename}
Compile the document to see the effect:
How it works...
After loading the tikz
package, we created a box to store the image. We defined a macro; its first task is to store our image...