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
  • 3,758
  • 18
  • 36

3 Answers3

3
GraphicsGrid[
 Partition[
  Join[PopupWindow[#, #] & /@ pictlist, 
   ConstantArray["", Mod[Length@pictlist, 8]]], 8], Frame -> All, 
 ImageSize -> 800]
Zviovich
  • 9,308
  • 1
  • 30
  • 52
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
  • 107,779
  • 16
  • 103
  • 257
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.
  • 70,533
  • 6
  • 140
  • 264