I have a large number of pictures, and I need to place each three of them in a grid with a certain layout. For example, if I have the following pictures:

p1 = 
p2 = 
p3 = 

The image dimensions of each is as follows:

ImageDimensions[#] & /@ {p1, p2, p3}

(* {{1024, 768}, {622, 468}, {970, 647}}  *)

I have resized the first 2 pictures:

{p11, p22} = ImageResize[#, 300] & /@ {p1, p2};

and now I want to place them together in one picture and then export them. I have tried Grid as follows:

all = Grid[{{p3, Column[{p11, p22}]}}]
Export["all.jpg", all]

The problem is that, Grid does not return the pictures in their correct size. So when I export, the result will be very small as seen in the pictures bellow. How can I get Grid to return the three pictures sized as I want?

enter image description here


Original answer

By default FrontEnd resizes graphics down inside list-like constructs. To prevent this inside Grid, set BaseStyle -> ImageSizeMultipliers -> 1 option for Grid:

all = Grid[{{p3, Column[{p11, p22}]}}, BaseStyle -> ImageSizeMultipliers -> 1];

Response to Mr.Wizard's comments

As Mr.Wizard notes in the comments, the ImageSizeMultipliers -> 1 does not fix another feature related to Image itself, citing the Documentation page for Image:

With Magnification->Automatic, smaller images are typically displayed at larger magnifications, and large images are reduced to fit within available notebook or other display areas.

Magnification->Automatic is the default option of Image, so if the whole Grid does not fit the screen area, all the images (sequentially starting from the largest one) are rescaled to fit the screen area. So more general workaround is:

all = Grid[{{p3, Column[{p11, p22}]}}] /. x_Image :> Image[x, Magnification -> 1]

If one wish to have Images always displayed and exported at their true sizes independently of any local or global Notebook's and FrontEnd's settings for the Magnification option, it is possible to achieve this by setting Magnification locally using Style:

   Grid[{{p3, Column[{p11, p22}]}}] /. x_Image :> Image[x, Magnification -> 1], 
   Magnification -> 1]

Now the magnification will be no longer affected by any local or global settings, for example

Magnify[%, 2]

Will display everything exactly at the original magnification.

  • $\begingroup$ Thanks a lot. this is what I am looking for. $\endgroup$ – Algohi Jun 6 '14 at 9:14
  • $\begingroup$ At least in version 7 this doesn't work (entirely). Rather than rendering large images at full pixel size it results in a scaling where all images fit on one screen width. Useful, but not what was requested. $\endgroup$ – Mr.Wizard Jun 6 '14 at 10:12
  • $\begingroup$ @Mr.Wizard I have added another, more general method. $\endgroup$ – Alexey Popkov Jun 6 '14 at 12:36
  • 1
    $\begingroup$ Indeed, that jogged a memory. Note that to override a Notebook magnification you'll also need a Style[. . ., Magnification -> 1]. $\endgroup$ – Mr.Wizard Jun 6 '14 at 13:12
  • $\begingroup$ @Mr.Wizard Thanks a lot to Mr. Wizard. your comments made the answers more solid and clear. $\endgroup$ – Algohi Jun 6 '14 at 21:29

In general, you can also use the ImageSize->All option for images to ensure that an image is always displayed full sized, even if it's in a list. So you could write:

all = Grid[{{Image[p3, ImageSize -> All], 
Column[{Image[p11, ImageSize -> All], 
  Image[p22, ImageSize -> All]}]}}]

(but I realize that's more typing in this specific case.)

  • 2
    $\begingroup$ This method works for me. You can simplify its application with this: Grid[{{p3, Column[{p11, p22}]}} /. x_Image :> Image[x, ImageSize -> All]] $\endgroup$ – Mr.Wizard Jun 6 '14 at 10:14
  • $\begingroup$ @Mr.Wizard this method and your simplification are very nice. $\endgroup$ – Algohi Jun 6 '14 at 21:28

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