Function Repository Resource:

DirectoryImagesViewer

Source Notebook

View image files from a given directory

Contributed by: Lou D'Andria

ResourceFunction["DirectoryImagesViewer"][dir]

scans the given directory for image files, and displays clickable thumbnails in a new viewer window.

Details and Options

ResourceFunction["DirectoryImagesViewer"] uses FileNames to scan the given directory for images whose FileFormat is a known image format.
Options relevant to the directory scan include:
"FileNamesDepth"1the directory depth for the FileNames scan
"FileFormats"{"PNG", "JPEG", "TIFF", "GIF", "HEIF"}file formats that are included in the scan
If no matching directory or files are found, ResourceFunction["DirectoryImagesViewer"] returns a Failure object.
The row of buttons in the thumbnail viewer notebook are formatted so they will linewrap to the width of the viewer notebook.
Options relevant to the thumbnails and the thumbnails viewer notebook include:
"ThumbnailFunction"(Thumbnail[#,150]&)function to create a thumbnail from a file path
"ThumbnailButtonOptions"{FrameMargins0, ImageMargins5, ImageSize{160,160}}options for each thumbnail button
"ThumbnailTooltip"Truewhether to display the file name as a tooltip for the thumbnail
"ThumbnailCellOptions"{}options for the cell containing the thumbnails buttons
"ThumbnailNotebookOptions"{}options for the thumbnail viewer notebook
Clicking on a thumbnail in the viewer imports the full image and displays it in a separate notebook window.
By default, the full image window is sized to fit in the primary display's dimensions, with the image scaled to fit in the window.
Images with dimensions less than the monitor's height will be prone to pixelation.
Options relevant to the full images and the full image window include:
"FullImageImportOptions"{ImageResolution72}options given to the call to Import
"FullImageDisplayFunction"Automaticfunction for processing the imported full image prior to display
"FullImageSize"AutomaticImageSize setting for the processed full image
"FullImageCellOptions"{TextAlignmentCenter}options for the cell containing the full image
"FullImageNotebookOptions"{}options for the notebook containing the full image
The thumbnail and full image for an animated GIF is based only on its first frame.

Examples

Basic Examples (2) 

View image files from a subdirectory of your home directory:

In[1]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}]]
Out[1]=

View image files from a subdirectory of $InstallationDirectory:

In[2]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "SlideShow"}]]
Out[2]=

Scope (1) 

If the given directory does not exist, DirectoryImagesViewer returns a Failure object:

In[3]:=
ResourceFunction["DirectoryImagesViewer"]["/Volumes/ssd/"]
Out[3]=

Options (18) 

FileFormats (1) 

Include only those image files which FileFormat recognizes as containing TIFF data:

In[4]:=
ResourceFunction["DirectoryImagesViewer"][
 DirectoryName @ FindFile @ "ExampleData/turtle.jpg", "FileFormats" -> {"TIFF"}]
Out[4]=

FileNamesDepth (2) 

There are no image files at the root level of $InstallationDirectory:

In[5]:=
ResourceFunction["DirectoryImagesViewer"][$InstallationDirectory]
Out[5]=

Change "FileNamesDepth" to search deeper within a directory:

In[6]:=
ResourceFunction["DirectoryImagesViewer"][$InstallationDirectory, "FileNamesDepth" -> 2]
Out[6]=

FullImageCellOptions (1) 

Set the frame, background and alignment of the cell containing the full image:

In[7]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$HomeDirectory, "Images"}], "FullImageCellOptions" -> {CellFrame -> 1, Background -> GrayLevel[0.9, 0.9], TextAlignment -> Center}];

FullImageDisplayFunction (2) 

The default "FullImageDispayFunction" uses a heuristic ImagePad before showing the image at the size specified by "FullImageSize":

In[8]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Product"}]];

"FullImageDisplayFunction"(#&) effectively turns off that padding:

In[9]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Product"}], "FullImageDisplayFunction" -> (# &)];

Arbitrary image processing functions can be used to process the full image before displaying:

In[10]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Product"}], "FullImageDisplayFunction" -> (ColorNegate[#] &)];

FullImageNotebookOptions (1) 

Display the full image in a frameless notebook which closes when clicked:

In[11]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$HomeDirectory, "Images"}], "FullImageNotebookOptions" -> {WindowFrame -> "Frameless", NotebookEventActions -> {"MouseClicked" :> NotebookClose[EvaluationNotebook[]]}}];

FullImageSize (2) 

By default, each full image is given an explicit ImageSize that will cause it to display within the current screen dimensions:

In[12]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$HomeDirectory, "Images"}]];

Other "FullImageSize" settings will display the full image at that size:

In[13]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$HomeDirectory, "Images"}], "FullImageSize" -> 500];

ThumbnailButtonOptions (2) 

Remove the frame from the thumbnail buttons, and align the thumbnail bottoms:

In[14]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailButtonOptions" -> {Appearance -> None, BaselinePosition -> Bottom}]
Out[14]=

The size of the thumbnail image and the size of the thumbnail button are controlled separately:

In[15]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailButtonOptions" -> {ImageSize -> {100, 100}}, "ThumbnailFunction" -> (Thumbnail[#, 50] &)]
Out[15]=

ThumbnailCellOptions (1) 

Set the margins and background of the cell containing the thumbnails:

In[16]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailCellOptions" -> {CellMargins -> 50, Background -> GrayLevel[0.9]}]
Out[16]=

ThumbnailFunction (3) 

Customize the function that turns the file path into a thumbnail:

In[17]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailFunction" -> (Thumbnail[#, Tiny] &)]
Out[17]=

The size of the thumbnail image and the size of the thumbnail button are controlled separately:

In[18]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailButtonOptions" -> {ImageSize -> {200, 200}}, "ThumbnailFunction" -> (Thumbnail[#, Large] &)]
Out[18]=

Arbitrary functions can be used to generate the thumbnail images:

In[19]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Product"}], "ThumbnailFunction" -> (ImageResize[
     ColorConvert[Import[#, "Image"], "Grayscale"], 125] &)]
Out[19]=

Use Rasterize to construct a thumbnail image that includes text or other expressions:

In[20]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Shaders", "HatchShading"}], "ThumbnailFunction" -> (Rasterize[
     Labeled[Thumbnail[#, 100], FileNameTake[#]]] &)]
Out[20]=

ThumbnailNotebookOptions (2) 

Make a viewer that looks and works like a standard palette window:

In[21]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailNotebookOptions" -> {WindowFrame -> "Palette", WindowClickSelect -> False, WindowFloating -> True, WindowMargins -> {{Automatic, 0}, {Automatic, 0}}, WindowSize -> {250, FitAll}, WindowTitle -> "Thumbnails"}]
Out[21]=

Automatically save the viewer notebook when it's created:

In[22]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailNotebookOptions" -> {NotebookFileName -> FileNameJoin[{$HomeDirectory, "ImageViewer.nb"}]}]
Out[22]=

ThumbnailTooltips (1) 

Turn off tooltips in the thumbnail viewer:

In[23]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailTooltips" -> False]
Out[23]=

Applications (1) 

Option settings for a particular idiomatic viewer:

In[24]:=
With[{dir = FileNameJoin[{$HomeDirectory, "Images"}]}, ResourceFunction["DirectoryImagesViewer"][dir, "ThumbnailTooltips" -> False, "ThumbnailNotebookOptions" -> {WindowClickSelect -> False, ShowCellBracket -> False, NotebookFileName -> FileNameJoin[{DirectoryName[dir], "SlidePicker.nb"}]}, "FullImageNotebookOptions" -> {WindowSize -> CurrentValue[$FrontEnd, ScreenRectangle][[All, 2]], WindowTitle -> "", WindowElements -> {"MagnificationPopUp"}}]]
Out[24]=

Possible Issues (2) 

If the thumbnail's size exceeds the button's ImageSize, the thumbnail will display as clipped:

In[25]:=
ResourceFunction["DirectoryImagesViewer"][
 FileNameJoin[{$HomeDirectory, "Images"}], "ThumbnailButtonOptions" -> {ImageSize -> {200, 200}}, "ThumbnailFunction" -> (Thumbnail[#, 500] &)]
Out[25]=

The default "FullImageDisplayFunction" can cause pixelation and odd alignment for images that are smaller than the display's native size:

In[26]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Product"}]];

Neat Examples (1) 

Show each full image at its native size:

In[27]:=
ResourceFunction["DirectoryImagesViewer"][
  FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Product"}], "FullImageSize" -> Magnification[1], "FullImageDisplayFunction" -> (# &), "FullImageNotebookOptions" -> {WindowElements -> {"HorizontalScrollBar", "VerticalScrollBar"}}];

Publisher

Lou D'Andria

Version History

  • 1.0.0 – 06 December 2021

License Information