3

I want to round corners of image and I want to have border around:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows.blur,fadings}

\tikzset{ 
  photo/.style={ inner sep=1pt,clip,rounded corners=0.5cm }
}

\begin{document}

\begin{tikzpicture}
  \node[photo] at (0,0)
    {\includegraphics[width=110mm]{chipping-sparrow-wiki-commons-1900x855.jpg}};
\end{tikzpicture}

\bigskip

\begin{tikzpicture}
  \node[photo,draw=red!80,thick] at (0,0)
    {\includegraphics[width=110mm]{chipping-sparrow-wiki-commons-1900x855.jpg}};
\end{tikzpicture}

\end{document}

The second tikzpicture gives me an error: ! Package tikz Error: Extra options not allowed for clipping path command..

And the result looks like this:(Image by DickDaniels, CC-BY-SA, from https://www.innonmillcreek.com/blog/2017/01/north-carolina-mountain-birds-chipping-sparrow.html)

I guess I could use \path and \node combination, but I don't know image size.

How can I get clipped image with border in this case?

3

The clipped image is a node and can be named (name=clipped). Later a rectangle can be drawn like this:

\draw (clipped.south west) rectangle (clipped.north east);

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows.blur,fadings}

\tikzset{ 
  photo/.style={inner sep=1pt,clip,rounded corners=0.5cm }
}

\begin{document}    
\begin{tikzpicture}
  \node[photo] at (0,0)
    {\includegraphics[width=110mm]{chipping-sparrow-wiki-commons-1900x855.jpg}};
\end{tikzpicture}

\bigskip

\begin{tikzpicture}
  \node[photo,name=clipped] at (0,0)
    {\includegraphics[width=110mm]{chipping-sparrow-wiki-commons-1900x855.jpg}};
  \draw[red,thick, rounded corners=0.5cm] (clipped.south west) rectangle (clipped.north east);
\end{tikzpicture}  
\end{document}
4

You can get the image height with the command:

\pgfdeclareimage[width=110mm]{image1}{/path/your/image}
\settoheight{\imageheight}{\pgfuseimage{image1}}

After, I added a rectangle node with your desired options:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shadows.blur,fadings}

\tikzset{ 
  photo/.style={ inner sep=1pt,clip,rounded corners=0.5cm }
}
\newlength\imageheight

\begin{document}
\pgfdeclareimage[width=110mm]{image1}{bird.jpg}
\settoheight{\imageheight}{\pgfuseimage{image1}}


\begin{tikzpicture}

  \node[photo] at (0,0)
   {\includegraphics[width=110mm]{bird.jpg}};
\end{tikzpicture}

\bigskip

\begin{tikzpicture}
  \node[photo] at (0,0)
    {\includegraphics[width=110mm]{bird.jpg}};
    \node (rect) at (0,0) [draw,thick,minimum width=110mm,minimum height=\imageheight,draw=red!80,thick,rounded corners=0.5cm] {};
\end{tikzpicture}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.