# Magnification of a notebook image object

When you resize an image in a notebook with your mouse you get a tool tip with size and a magnification percent for your image: Is there some way to programmatically ascertain these values in the tooltip? The values (both in the tooltip and the toolbar) seem to change along with the Magnification of the notebook. Note that ImageDimensions is not the solution here: • It's kinda boring. Go to the output cell containing your resized image and type in ImageDimensions @ before the image. Then evaluate as usual. – J. M.'s technical difficulties Apr 15 '16 at 0:20
• No, that's not what I mean, I'm looking for the numbers in the tool tip. – M.R. Apr 15 '16 at 0:24

Here is another solution in the spirit of the answer by M.R. (should work starting from Mathematica version 7):

AbsoluteImageDimensions[img_Image] :=
Module[{m = CurrentValue[Magnification], w0, h0, w},
{w0, h0} = ImageDimensions[img];
w = Options[img, ImageSize][[1, 2, 1]];
{m {w, w*h0/w0}, 100 (m w/w0)^2}] And here is a better version which handles the most of practical cases with exception to the situation when the image wasn't resized by hand but was resized due to the ImageSizeMultipliers option (in this case it simply ignores the result of applying of this option; note that if the image was resized by hand this option does not matter) or using the internal Magnification option of the Image (which is always Automatic if the image was resized by hand, i.e. does not affect the result):

AbsoluteImageDimensions[img_Image] :=
Module[{m = CurrentValue[Magnification], w0, h0, is, w, h},
{w0, h0} = ImageDimensions[img];
is = Options[img, ImageSize][[1, 2]];
Switch[is,
Automatic | {Automatic, Automatic}, {w, h} = {w0, h0},
{_?NumericQ, _}, {w, h} = {is[], is[]*h0/w0},
{_, _?NumericQ}, {w, h} = {is[]*w0/h0, is[]}
];
{m {w, h}, 100 (m w/w0)^2}] Here is one approach (Mathematica version 10 is required). Paste the following code as the next cell after the cell with your image and evaluate:

cell = NotebookRead[PreviousCell[]];
m = CurrentValue[Magnification]
Cases[cell,
GraphicsBox[__,
OrderlessPatternSequence[ImageSize -> {w_, _}, ___,
ImageSizeRaw -> {w0_, h0_}], ___] :> {m {w, w*h0/w0}, 100 (m w/w0)^2}, Infinity]

1.5

{{{273., 273.}, 331.24}} Note that the implementation of the image editing toolbar is contained in file

FileNameJoin[{\$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources",
"AttachedImage2D.nb"}]


Using Alexey's pattern:

AbsoluteImageDimensions[img_] :=
Module[{m = CurrentValue[Magnification]},
Cases[{ToBoxes@img},
GraphicsBox[___,
OrderlessPatternSequence[
Verbatim[Rule][ImageSizeRaw, {w0_, h0_}],
Verbatim[Rule][PlotRange, _],
Verbatim[Rule][ImageSize, {w_, _}]]] :> {m {w, w*h0/w0},
100 (m w/w0)^2}, \[Infinity]]
]  • You don't need Verbatim in the pattern: it works reliably as written in my first answer. Also please see my new answer. – Alexey Popkov Apr 21 '16 at 12:41