Can anyone explain why Row and Grid don't size the image correctly and consistently to 300 as specified in ImageResize?

image = ImageResize[Import["ExampleData/lena.tif"], 300];
Row[{"abcd", image}]
Grid[{{"abcd", image}}]

enter image description here

GraphicsGrid doesn't seem to help either.

Any workarounds to do so?

  • 3
    $\begingroup$ because you can paste images and use them as expressions just like anything else. The actual image size information is stored in the option ImageSizeRaw. When you say "GraphicGrid doesn't help either" what exactly do you want as the outcome? $\endgroup$ – Mike Honeychurch Jan 27 '15 at 4:42
  • $\begingroup$ I've received (as of this comment) 2 useful but different workarounds. Mr.Wizard's the simplest and most direct and Mike's a bit more versatile in that it gives one additional control for sizing. How to chose? $\endgroup$ – Jagra Jan 27 '15 at 23:30
  • 1
    $\begingroup$ @Mr.Wizard restores the actual image size without you have to know that actual size so would be a preferred option if that is all you need to do. $\endgroup$ – Mike Honeychurch Jan 28 '15 at 0:27
  • $\begingroup$ @MikeHoneychurch - We should have a badge for sportsmanship! Many thanks. $\endgroup$ – Jagra Jan 28 '15 at 2:25
  • $\begingroup$ just calling it the way i see it $\endgroup$ – Mike Honeychurch Jan 28 '15 at 2:51

Another approach (from this answer) is to re-set the value of the option ImageSizeMultipliers to {1.,1.} :

enter image description here

image = ImageResize[Import["ExampleData/lena.tif"], 250];
image2 = ImageResize[ExampleData[{"TestImage", "Mandrill"}], 150];

With the default settings

Grid[{{"abcd", image, image2}}]


enter image description here

After evaluating

SetOptions[EvaluationNotebook[], ImageSizeMultipliers -> {1., 1.}]

anywhere in the notebook, we get

enter image description here

You can reset the option value to its default using:

SetOptions[EvaluationNotebook[], ImageSizeMultipliers -> {.5, .25}]

An alternative, more cumbersome, approach is to wrap each object with Style[#, ImageSizeMultipliers->{1.,1.}:

dontResizeF = Style[#, ImageSizeMultipliers -> {1., 1.}] &;
Grid[{{"abcd", dontResizeF@image, dontResizeF@image2}}]

enter image description here

  • $\begingroup$ Thanks for this. This gives one a much better idea about what Mathematica might actually do under the hood. It does seem odd, that the default values of ImageSizeMultiplier don't equal {1.,1.}. $\endgroup$ – Jagra Mar 9 '15 at 13:28
  • $\begingroup$ Jagra, my pleasure. The default value makes using images/graphs in Input cells more convenient. I agree with you that, for output cells, default value of 1 would make more sense. $\endgroup$ – kglr Mar 9 '15 at 13:54
  • $\begingroup$ I've decided to select your answer as the best one (sorry @Mr.Wizard), because while the others provide workarounds, this one actually provides some insight and explanation of why the problem occurs. Thanks again. $\endgroup$ – Jagra Mar 9 '15 at 22:29
  • $\begingroup$ @Jagra No problem! I encouraged kguler to (re)post this here. I agree it is the best answer. For application to one item at a time I'll still use Pane, but it is a side-effect rather than the specific purpose of that construct, unlike the Option described here. $\endgroup$ – Mr.Wizard Mar 10 '15 at 2:23
  • $\begingroup$ @Jagra, thank you for the Accept. $\endgroup$ – kglr Mar 10 '15 at 8:57

My standard(1) work-around for this problem is to add Pane:

Row[{"abcd", Pane@image}]
Grid[{{"abcd", Pane@image}}]

enter image description here

A default characteristic of Pane is that it still allows resizing its contents to fit the window width of the Notebook. I find this a desirable default behavior. However if clipping is preferred you can specify an absolute width for Pane, or use ImageSize as Mike Honeychurch proposed.

Grid@{Table[image, {2}]}
Grid@{Table[Pane@image, {2}]}
Grid@{Table[Pane@image, {3}]}
Grid@{Table[Pane[image, 300], {3}]}

enter image description here

For more control see:


As per my comment you will note that images can be pasted into notebooks and used as expressions. They are not rendered at full size but the size information is stored as an option. If all you want to do is have Row and Grid render something to the same specific size then try Show:

Row[{"abcd", Show[image, ImageSize -> 300]}]
Grid[{{"abcd", Show[image, ImageSize -> 300]}}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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