From a previous question (\includegraphics: get the "scale" value of a figure whose size is expressed by "width") I learned how to get the scale factor of a figure inserted by the \includegraphics command.
Now I'd like to print, as a watermark, the scaling value on each figure in my document. I started from this:
\documentclass{article}
\pdfoutput=1
\usepackage{graphicx}
\usepackage{color}
\makeatletter
\let\ORG@Gscale@box\Gscale@box
\long\def\Gscale@box#1{%
\xdef\thelastscalefactor{#1}%
\ORG@Gscale@box{#1}}
\makeatother
\begin{document}
\includegraphics[width=0.4\textwidth]{example-image}
\colorbox{red}{\the\thelastscalefactor}
\end{document}
The best solution would be to redefine the \includegraphics command to do this but it would be ok also to define a \myincludegraphics command like in another issue of mine https://tex.stackexchange.com/a/455293/33634.
Finally I also have an issue with the string \the\thelastscalefactor:
! You can't use `the character 0' after \the.
\thelastscalefactor ->0
.3437




\let\oldincludegraphics\includegraphicsand using\renewcommand\includegraphics[2][]{...instead so you can keep the\includegraphicscommands in the rest of the file. – Gabriele May 23 '19 at 21:37