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:
Use FileNameTake to see the file names without the full path:
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:
Change the current working directory to the newly created temporary directory:
Import one of the images from the source directory:
Use Thumbnail with "Tiny" to create a very small thumbnail version of the original image:
Save the thumbnail using Export. You must specify the file name to save to, the image to export (th in this case), and its file format:
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:
Use FileByteCount to determine the byte count of each thumbnail:
For comparison, here are the byte counts of the original files: