# How to make “Show” function display images with original size?

h = ExampleData[{"TestImage", "House"}];
Grid[{{Show[h],
Show[h, Graphics[Line[{{0, 0}, ImageDimensions[h]*2}]],
PlotRange -> All]}}]


The second image is much smaller than the first. I want those two images to have same sizes.

Attempt 1

h=ExampleData[{"TestImage","House"}];
hDim=ImageDimensions[h];
a=Grid[{{Show[h,PlotRange->hDim],Show[h,Graphics[Line[{{0,0},hDim*2}]],PlotRange->All]}}]


Basically, it works. But the size of two images are still slightly different. Besides, it seems that I can not control the size any more, like use ImageSize.

• remove PlotRange-> All and check – Ali Hashmi May 27 '17 at 13:29
• But then I can not see the entire line. – Shen Zhou May 27 '17 at 13:39
• Grid[{{Show[h, PlotRange -> ImageDimensions[h]], Show[h, Graphics[Line[{{0, 0}, ImageDimensions[h]*2}]], PlotRange -> All]}}] – Ali Hashmi May 27 '17 at 13:50
• Thanks for your reply. But it still not perfect. And this problem looks like an easy one. But I still can not find a perfect solution after couples of hours struggling. – Shen Zhou May 27 '17 at 23:40
• Grid[{{Show[h, PlotRange -> hDim], Show[h, Graphics[Line[{{0, 0}, hDim*2}]], PlotRangePadding -> 0, PlotRange -> All]}}]? – kglr May 27 '17 at 23:53

You can make use of the new in M8 ImageSize syntax to do this:

h = ExampleData[{"TestImage","House"}];
hDim = ImageDimensions[h];
a = Grid[
{{
Show[h, ImageSize->hDim->200],
Show[h, Graphics[Line[{{0,0}, hDim*2}]], ImageSize->hDim->200,
]
}},
Alignment->Bottom
]


• Thanks a lot. Sorry for not voting due to my low reputation. – Shen Zhou May 28 '17 at 0:11

We can take control of the image size with ImagePad to resize the images and with the ImageSize -> option of the Show command. Here is some code that illustrates the approach.

ClearAll["Global*"]

h = ExampleData[{"TestImage", "House"}];
{wd, ht} = ImageDimensions[h];

imgLeft = ImagePad[h, {{0, 0}, {0, ht}}, White];
sizeLeft = ImageDimensions[imgLeft];

imgRight = ImagePad[h, {{0, wd}, {0, ht}}, White];
sizeRight = ImageDimensions[imgRight];

line = Graphics[{Line[{{0, 0}, ImageDimensions[imgRight]}]}];
m = 1/2;

Grid[{{
Show[imgLeft, ImageSize -> m*sizeLeft],
Show[{imgRight, line}, ImageSize -> m*sizeRight]}},
Alignment -> {{Left, Left}, {Bottom}},
Frame -> All]


We use the Frame -> All option initially to see the image spacing, borders, etc, and remove it later.

To create the images at the same scale, we first note that the diagonal line is the diagonal of an image that is twice as large as the original. Knowing that, we pad the original to be the same width and height as the line to obtain an image for the right panel. Padding does not distort the original. For the left image we pad the original to the same height as right image. The padding is only applied to the right and at the top of the original.

We can introduce a "magnification factor", $m$, to control the overall size of the images. The magnification is applied in the ImageSize -> option of the Show commands.

Note that the GraphicsGrid command is similar to Grid` command but seems to introduce additional, unwanted padding.