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.
Mathematica'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
Mathematica.
First, get a list of all the images at a specified location. This finds the images in the
Mathematica ExampleData directory, and returns the full path for each:
Use
FileNameTake to see the file names without the full path:
| Out[2]= |  |
You can now create thumbnails from each image and save them in an alternate directory. Here, a directory is created from within
Mathematica. Conveniently,
CreateDirectory creates a directory in the default area for temporary directories on your computer system:
Change the current working directory to the newly created temporary directory:
Import one of the images from the source directory:
Use
Thumbnail with

to create a very small thumbnail version of the original image:
| Out[4]= |  |
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:
| Out[5]= |  |
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:
| Out[4]= |  |
Use
FileByteCount to determine the byte count of each thumbnail:
| Out[5]= |  |
For comparison, here are the byte counts of the original files:
| Out[6]= |  |
Import all thumbnail images:
| Out[7]= |  |