2
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ Partition[Range[20], 8, 8, 1, {}], I don't know why this isn't a default behaviour. $\endgroup$
    – Kuba
    Mar 9 '15 at 14:57
  • $\begingroup$ Regarding clicability, this answer using Button could be useful: mathematica.stackexchange.com/a/2725/131. $\endgroup$
    – Yves Klett
    Mar 9 '15 at 16:49
  • $\begingroup$ The PopupWindow docs under Applications has an example of this. Just wrap Grid around the list. $\endgroup$ Mar 10 '15 at 0:59
3
$\begingroup$
GraphicsGrid[
 Partition[
  Join[PopupWindow[#, #] & /@ pictlist, 
   ConstantArray["", Mod[Length@pictlist, 8]]], 8], Frame -> All, 
 ImageSize -> 800]
$\endgroup$
3
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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