Creating an image grid that displays a full-size image when a thumbnail in the grid is clicked on

2

I am working on some teaching resources and pulled a whole bunch of images off the internet to illustrate the idea of "angle".

I can get Mathematica to import them and display them in a nice "collage", a kind of "preview" image with all the picture files.

dir = NotebookDirectory[];
picturedir = FileNameJoin[{dir, "Pictures"}];
pictlist = Import /@ FileNames[{"*.jpg", "*.png", "*.gif"}, {picturedir}];
GraphicsGrid[Partition[pictlist, 8], Frame -> All, ImageSize -> 800]

I have two questions.

First. When I partition the list, how can I get it to "pad" and simply leave a blank space in the grid if the number of images isn't a multiple of 8?

Second, the more important question. Could I make the GraphicsGrid "clickable", so I could click on the small image in my collage and have it open the full size image in another Mathematica notebook for better viewing?

Tom De Vries

Posted 2015-03-09T12:24:27.880

Reputation: 3 628

Partition[Range[20], 8, 8, 1, {}], I don't know why this isn't a default behaviour. – Kuba – 2015-03-09T14:57:43.100

Regarding clicability, this answer using Button could be useful: http://mathematica.stackexchange.com/a/2725/131.

– Yves Klett – 2015-03-09T16:49:50.837

The PopupWindow docs under Applications has an example of this. Just wrap Grid around the list. – Mike Honeychurch – 2015-03-10T00:59:32.457

Answers

3

GraphicsGrid[
 Partition[
  Join[PopupWindow[#, #] & /@ pictlist, 
   ConstantArray["", Mod[Length@pictlist, 8]]], 8], Frame -> All, 
 ImageSize -> 800]

Zviovich

Posted 2015-03-09T12:24:27.880

Reputation: 8 824

3

Here is a simple way to do it usingMulticolumn, which is new in V10. I use a 4 x 4 grid with a list of three pictures

pics

Multicolumn[
  Item[PopupWindow[#, #, WindowSize -> {All, All}], ItemSize -> 10] & /@ pictlist, 
  2, 
  Frame -> All]

grid

And clicking on one the thumbnails produces

popup

m_goldberg

Posted 2015-03-09T12:24:27.880

Reputation: 104 223

2

Here's a small example:

image := Graphics[{Hue@RandomReal[], Rectangle[]}, ImageSize -> 50]
images[n_] := Partition[PadRight[Table[image, {n}], n + 8 - Mod[n, 8], Null], 8];

Color grid

The key is that Null gives a blank space when used in GraphicsGrid. I agree with Zviovich that PopupWindow is the best way to achieve what you ask for when it comes to displaying the images in a larger size. If I were to extend my example to include that I might use

Deploy@GraphicsGrid@Map[
   MouseAppearance[PopupWindow[#, #], "LinkHand"] &,
   images[60],
   {2}
   ]

where Deploy and MouseAppearance are just there to add niceties. See also the example under "Applications" in the documentation for PopupWindow.

C. E.

Posted 2015-03-09T12:24:27.880

Reputation: 67 448