# How to get the size of a specific image in the front end?

The title pretty much says it all.

One possible point of confusion is that this question is not limited to items with head Image.

I don't know what is the official terminology for what I'm referring to, but I can describe it operationally: if I click on a "graphic-type" (Graphics, Graphics3D, Image, etc.) thingie being displayed by the front end, usually1 an orange outline appears around it, featuring "drag handles" at its corners and mid-sides. My question here is: how can I get the current, actual image size of such a thing?

Also, I'm not interested in ways to answer this question that rely on deducing this size from knowledge of the default behaviors of the code that produced the output. Rather, I'm looking for a method that somehow interrogates the actual item shown on the screen.

1 One exception is the output of, say, GraphicsGrid, which, depending on where one clicks on it, can get a thick gray outline around the whole grid, or an orange outline around the content of an individual cell.

• Does the function PredictionsgetImageSize give what you need? – kglr Jun 27 '15 at 21:26
• @kglr: Marvelous. Thanks! – kjo Jun 27 '15 at 22:44
• Note that PredictionsgetImageSize[graphic] is equivalent to well-documented Rasterize[graphic, "RasterSize"] (as can be found by looking at the Definition of PredictionsgetImageSize). – Alexey Popkov Jun 28 '15 at 5:22
• I notice that PredictionsgetImageSize won't work if Suggestions Bar is disabled. – SquareOne Jun 28 '15 at 8:18

kglr's very useful trophy from the land of undocumented functions needs to be recorded.

Suppose you have the following plot:

Plot[Sin[2 Pi t], {t, 0, 1}, ImageSize -> Tiny]


Then you can just cut and paste

{100, 54}


Note, however, that PredictionsgetImageSize actually reports ImageSize plus ImageMargins, as shown in the listing below. (The following abbreviations are used in the headings: PredgIS= reported by PredictionsgetImageSize; IS= specified ImageSize; PRP= specified PlotRangePadding; IP= specified ImagePadding; IM=specified ImageMargins; the ImageSize was adjusted as necessary so as to keep the size of the plotted function graph invariant.)

FWIW, here's the code that generated the listing above.

example[size_, prPadding_, padding_, margins_] := Module[{plot},
plot =
Plot[Sin[2 Pi t], {t, 0, 1}, Frame -> True,
ImageSize -> size];
margins}
];

Grid[Join[{{"PredgIS", "Sin[2 Pi t]", "IS", "PRP", "IP", "IM"}},
example @@@
{
{100,          0,            0,  0},
{100/0.8,      Scaled[0.1],  0,  0},
{60 + 100/0.8, Scaled[0.1], 30,  0},
{60 + 100/0.8, Scaled[0.1], 30, 15}
}],
Alignment -> Left,
Dividers -> {All, {True, True, False, False, False, True}},
Spacings -> {2, 2}]
`