[Tex/LaTex] Pictures in boxes with rounded corners

tcolorbox

I am using the tcolorbox LaTeX package to create some boxes with rounded corners. Everything works well when text goes in those boxes.

But I want to fill some of those boxes with just a picture (usually jpg format). Using \includegraphics inside the box indeed puts the picture in the box, but the rectangular picture does not have the rounded corners that I want. In other words, I want the corners of the picture to become rounded and not spill outside the box with rounded corners.

I would be grateful if someone can let me know how to do this. It would be nice to do so in tcolorbox, but I am also open to other solutions.

Thanks!

Best Answer

Since tcolorbox is implemented using tikz, this is actually simpler.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\sbox0{\includegraphics{example-image}}%
\path[clip,draw,rounded corners=1.5cm] (0,0) rectangle (\wd0,\ht0);
\path (0.5\wd0,0.5\ht0) node[inner sep=0pt]{\usebox0};
\end{tikzpicture}
\end{document}

demo

Related Question