5

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 = 
  Import["http://images4.fanpop.com/image/photos/21900000/Beautiful-\
    Pictures-_-beautiful-pictures-21967793-1024-768.jpg"];
p2 = 
  Import["http://static.ddmcdn.com/gif/ice-ice-babies-pictures-2.jpg"];
p3 = 
  Import["http://latimesphoto.files.wordpress.com/2012/08/la-0824-pin01.jpg"];

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78

2 Answers2

10

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:

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.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
3

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.)

Niki Estner
  • 36,101
  • 3
  • 92
  • 152