TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following example works in so far as it shows the image in the source latex file and disregards everything else. Is there some way of performing the same task but also list information about each image such as its the dimensions, file size and filename below each image? Only the preview should have that.

I am hoping that not only can I accomplish that but that I don't have to manually type in the file size and other info myself -- although if there is no way to grab the info automatically then the next best would be to add the info manually. Either way, I would like to know how to accomplish this.







Result (the grey part around the image was not part of the output but is an artifact of my capturing process so that part can be disregarded):


(Creative Commons info on elephant image available here .)

share|improve this question
up vote 15 down vote accepted

The following solution redefines \includegraphics (in the form with one optional argument) and prints extra data below the image if preview is loaded and active. Since version 1.30 pdfTeX has some nice commands that extracts file modification date, file size or the MD5 sum of the file.

The image sizes are get by graphics \Gin@nat@width and \Gin@nat@height. However they get modified by option trim, for example. Perhaps more clear is the "final image size". It is just the size that the image occupies on the paper. It is measured by putting the \includegraphics in a box.


% Store the old meaning of \includegraphics
\usepackage{letltxmacro}% safer variant

% \FileName{<file>} prints the file name

% Packages for extracting and printing file meta data
% (for pdfTeX and LuaTeX in both modes)

    % catch the right file name by hooking into \@addtofilelist
    % that is called by \includegraphics
    \gdef\graphics@filename{#2}% default
    \begin{tabular}{@{}l@{ }l@{}}%
      \LaTeX\ name: & \FileName{#2}\tabularnewline
      File name: &
      File date: &
      File size: &
      File MD5 sum: &
      Natural image size: & \graphics@natsize\tabularnewline
      Final image size: &
      \the\dimexpr\ht\graphics@box + \dp\graphics@box\relax


% if package preview is loaded and active,
% \ifPreview is defined and true.
  % otherwise switch to unchanged behaviour of \includegraphics







enter image description here

share|improve this answer
I'm speechless. Absolutely brilliant. :) I wrote a humble code trying to answer this question - My idea was to call the external identify command from ImageMagick via \write18 and then gather the output. My code is not even close to your majestic answer. :) Thanks a million for joining us, it's really an honour to have you here. :) – Paulo Cereda Jul 29 '12 at 14:33
@Paulo, Even though Heiko's answer is amazing I would still be interested at looking at other approaches too even if they are not as good. – user1189687 Jul 31 '12 at 20:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.