How to | Create a Folder of Thumbnail Images

A very common batch processing task is to reduce the dimensions of a set of images in one or more system folders, in effect constructing thumbnail images. The Wolfram Language's file operations, Import, Export, and Thumbnail, combine to give you an effective way to do this programmatically. In fact, Import and Export are integral to most batch processes in the Wolfram Language.

First, get a list of all the images at a specified location. This finds the images in the Wolfram System ExampleData directory, and returns the full path for each:

In[1]:=
Click for copyable input

Use FileNameTake to see the file names without the full path:

In[2]:=
Click for copyable input
Out[2]=

You can now create thumbnails from each image and save them in an alternate directory. Here, a directory is created from within the Wolfram System. Conveniently, CreateDirectory creates a directory in the default area for temporary directories on your computer system:

In[3]:=
Click for copyable input

Change the current working directory to the newly created temporary directory:

In[4]:=
Click for copyable input

Import one of the images from the source directory:

In[5]:=
Click for copyable input

Use Thumbnail with to create a very small thumbnail version of the original image:

In[6]:=
Click for copyable input
Out[6]=

Save the thumbnail using Export. You must specify the file name to save to, the image to export ( in this case), and its file format:

In[7]:=
Click for copyable input
Out[7]=

Using any suitable looping construct, this sequence of steps can be performed on any number of files and directories. Collect the individual steps in a single nested expression and iterate over all the files in the chosen directory:

In[8]:=
Click for copyable input
Out[8]=

Use FileByteCount to determine the byte count of each thumbnail:

In[9]:=
Click for copyable input
Out[9]=

For comparison, here are the byte counts of the original files:

In[10]:=
Click for copyable input
Out[10]=

Import all thumbnail images:

In[11]:=
Click for copyable input
Out[11]=