# Get the width of a picture with Tikz

I 'm trying to make a presentation with beamer and I use Tikz to incorporate pictures at some places in my frames.

For some reasons, I would like to fixe the heigth of a picture (contained in a node) and retrieve the width of this picture (to draw a specific background for this picture.

Is it possible to get the width of a picture or a node inside a tikzpicture environnement (lengt is supposed to be my retrieved value from pic node) :

\begin{tikzpicture}[anchor=south east,inner sep = 0, outer sep = 0,overlay]
\node (pic) at (0,0) {\includegraphics[height=1.2\baselineskip,keepaspectratio]{mypicture.pdf}};
\draw [fill=couleurprimaire,couleurprimaire] (-\lengt,0) rectangle (\lengt,2\baselineskip);
\end{tikzpicture}

• You should include the whole code, since we don't have "couleurprimaire" or "keepaspectratio". :D Also, I'm not sure what you want to do. – Alenanno Jul 7 '15 at 18:52

You can get the width of something like text of a picture with \settowidth

\documentclass{beamer}

\usepackage{tikz}

\begin{document}

\begin{frame}

\newlength{\picwidth}
\settowidth{\picwidth}{\includegraphics[height=1.2\baselineskip,keepaspectratio]{pic.pdf}}

\begin{tikzpicture}[anchor=south east,inner sep = 0, outer sep = 0,overlay]
\node (pic) at (0,0) {\includegraphics[height=1.2\baselineskip,keepaspectratio]{pic.pdf}};
\draw [fill=blue] (-\picwidth,0) rectangle (\picwidth,2\baselineskip);
\end{tikzpicture}

\end{frame}

\end{document}