Home > How-Tos > Resizing and Renaming Batches of Images

Resizing and Renaming Batches of Images

April 7th, 2010

I recently had the need to resize a hundred jpeg images of varying sizes, and to get them all down to consistent widths (or heights for the portrait images), and then finally to rename the thumbnail preview images that I had also created.


My first thought was that I could use Gimp, but alas it does not by default have a batch conversion process. There is a plug-in called “David’s Batch Processor”, but it doesn’t allow you to specify just the X or Y dimension by itself.

The resizing tool I went for was ‘mogrify‘, which is a command line utility with awesome image manipulation capabilities. Since I wanted to get all my landscape format images down to 400 pixels wide, I just entered the following command:

mogrify -resize 400 *.jpg

For the portrait images that I wanted to all be 400 pixels high I entered:

mogrify -resize x400 *.jpg


Once I had all the images resized, I wanted to set the names of my preview thumbnails to end ‘_pre.jpg’. It turns out that this is very easy to do with the ‘rename’ command, which was written by the creator of Perl – Larry Wall. The command is included by default with Debian and Ubuntu, and is easily added to other distros.

Just supply ‘rename’ with a regular expression, and it renames your files as required. The important part of the command parameter is:

's/ [pattern to match] / [what to replace it with] /'

To rename my images I just entered:

rename -v 's/\.jpg$/_pre\.jpg/' *.jpg

To test the command without actually renaming anything, just change ‘-v’ to ‘-n’.

For more information on the ‘rename’ command see http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal

Categories: How-Tos Tags: , , , ,
Comments are closed.