Frame option in includegraphics makes an overfull \hbox

Here's how you can do; which one to choose between the second and third example is a matter of taste and of what your pictures contain.

The frame option draws a frame with rule of width \fboxrule (by default) and zero space between the frame and the box. But the rule width is added to the width of the box, so you have to do something about it: either reduce a bit the width of the box, or draw the frame inside the box, by specifying a negative separation (second parameter to the frame option).

\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\setlength{\parindent}{0pt} % just for the example

\begin{document}

\footnotesize

% first example: bad, there's an overfull of twice the rule width    
\verb|\includegraphics[width=\textwidth,frame]{tiger}|\\
\begin{minipage}{4cm}
\includegraphics[width=\textwidth,frame]{tiger}
\end{minipage}

\medskip

% second example: good, the frame is drawn outside the picture
\verb|\includegraphics[width=\dimexpr\textwidth-2\fboxrule,frame={\fboxrule}]{tiger}|\\
\begin{minipage}{4cm}
\includegraphics[width=\textwidth-2\fboxrule,frame={\fboxrule}]{tiger}
\end{minipage}

\medskip

% third example: good, the frame is drawn inside the picture
\verb|\includegraphics[width=\textwidth,frame={\fboxrule} {-\fboxrule}]{tiger}|\\
\begin{minipage}{4cm}
\includegraphics[width=\textwidth,frame={\fboxrule} {-\fboxrule}]{tiger}
\end{minipage}
\end{document}

Don't include the minipage environments, they are just to show the effect while using \textwidth (that's reset in a minipage) and not having a huge picture of the result.

enter image description here

Defining a command for this kind of job is quite easy:

\newcommand{\twincludegraphics}[2][]{%
   \includegraphics[
     width=\dimexpr\textwidth-2\fboxrule,
     frame={\fboxrule},
     #1]{#2}%
}

so you can call

\twincludegraphics{tiger}

or

\twincludegraphics[<other options>]{tiger}

where <other options> might even countermand the default ones for special cases.


You don't say what you want to happen, without adjustbox then

\frame{\includegraphics[width=\textwidth]{...}}

will make a frame that overprints the edge of the image, so the resulting combination is still just \textwidth wide and will fit on the page

\fbox{\includegraphics[width=\textwidth]{...}}

will make a border around the outside of the image so the resulting combination is too wide by the width of the padding and border on each side, so you need

\fbox{\includegraphics[width=\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax]{...}}

So the resulting combination is \textwidth wide.

Or perhaps you want the image full width and the frame in the margin

\hspace*{\dimexpr-\fboxsep-\fboxrule}%
\fbox{\includegraphics[width=\textwidth]{...}}%
\hspace*{\dimexpr-\fboxsep-\fboxrule}%