 \documentclass{article}


\newlength{\myfigurewidth}
\newsavebox{\myfigure}

\newcommand{\Testwidth}[1]
{
\savebox{\myfigure}{#1}
\settowidth{\myfigurewidth}{\usebox{\myfigure}}
{#1}

width of figure is: \the\myfigurewidth\\
}
    \begin{document}



    \Testwidth
    {\rule{200pt}{100pt}}
    
    
\begin{figure}[!ht]
\centering
\rule{200pt}{100pt}

\parbox[c]{\the\myfigurewidth}{\caption{caption text caption text caption text caption text 
caption text caption text caption text caption text caption text 
caption text caption text caption text caption text caption text }}
\end{figure}


    \end{document}

     