I am trying to read the size of a PDF file to adjust the size of the next page to the size of the figure. I have had some success, but the figure is still not well adjusted. I could adjust this figure, but I want to automate the adjustment, as I have 150 figures to insert in the file. I also need to add an extra height on the page, to place the caption of the figure. Any suggestion?

%-----------------------------------------------------------------
\setbox0 = \hbox{\includegraphics{01.pdf}}
width = \the\wd0, height = \the\ht0

\newpage
%================================================================================
\eject \pdfpagewidth=\the\wd0 \pdfpageheight=\the\ht0

\begin{figure}
\caption{<name picture>}
\includegraphics{01.pdf}
\end{figure}


Here is an attempt using \igrgraph command from incgraph pacakge.

\igrgraph{<text>} automatically typesets <text> in a separate page with height and width the same of <text>, so you don't need to manually change page size.

\documentclass{article}
\usepackage{incgraph}
\usepackage{caption}

\begin{document}
text on first page
\igrpage{%
\setbox0=\hbox{\includegraphics{example-image}}%
\begin{minipage}{\wd0}
\captionof{figure}{figure on second page}
\box0\relax
\end{minipage}%
}
text on third page
\end{document}


This generates a three-page pdf, of which the second page is

with the help of the answer below:

https://tex.stackexchange.com/a/268919/134993

I write:

%---------------------------------------------------
\newsavebox{\measurebox}
\newlength{\measuredwidth}
\newlength{\measuredheight}
\newcommand\measureimage[2][1]{%
\savebox{\measurebox}{\includegraphics[page=#1]{#2}}%
\setlength{\measuredwidth}{\wd\measurebox}%
\setlength{\measuredheight}{\ht\measurebox}%
\savebox{\measurebox}{}%
} %-----------------------------------------------------------------------
\measureimage[1]{01.pdf} % measures the 1nd page of the file.

\newpage

\newgeometry{left=0mm,right=0mm,top=0cm,bottom=0cm}
\eject \pdfpagewidth=\measuredwidth \pdfpageheight=\measuredheight

\begin{figure}[h]
\includegraphics{01.pdf}
\caption{caption picture}
\end{figure}
%-----------------------------------------------------------------------


TO DO: I still have to find out a way to insert a space below the figure to place the caption.

Any suggestions?