# Scaling an image to the size of a character [duplicate]

I use this code to place an image next to a character while matching its size:

\documentclass{article}

\usepackage{mwe}
\newlength{\Height}
\newlength{\Depth}
\DeclareRobustCommand{\ScaleImage}[1]{%
\def\temp{#1}\ifx\temp\empty
\PackageWarning{Eu}{Empty character given}%
\fi
\raisebox{-\depth}{%
\vphantom{#1}%
\settoheight{\Height}{#1}%
\settodepth{\Depth}{#1}%
\includegraphics[height=\Height]{example-image-a}%
}}

\begin{document}
\dots \ScaleImage{!}!

\dots) \ScaleImage{)}

an \ScaleImage{a} anonymous \dots

\dots fooling around, \ScaleImage{,}

\ScaleImage{}
\end{document}


This is how this looks:

It works pretty well, but note, for example, the example with the exclamation mark, which exceeds the size of the red box. Am I missing something, or is there some discrepancy between how a character is measured and how it is printed?