code warehouse


Table of contents

imresize is a program which can resize and/or convert images.


Standard usage: [options] <file1> [<file2>...<fileN>]

If you do not pass any option, imresize will merely copy files to the default output directory (and possibly optimize and/or change the quality of the files). This is therefore an interesting substitute for cp.

Hopefully, imresize comes with a handful of options which let you resize and/or convert images in only one command line. Note that the examples below do not include a list of files to process, for simplicity's sake, though this is not an optional argument.


This option prints an helpful text which describes the options. It also prints the list of supported image file formats. (See the -f <image-format> option below.)

-s <width>,<height>

This option lets you change the size of the generated images. The following command will thus resize all images so that they are 300px wide and 200px high: -s 300, 200

If <width> or <height> is omitted, the program computes the missing value from the given one, so that the proportion of the original images are kept. For example, if you want to scale images so that they are 300px wide, you would use the following command: -s 300,

Similarly, if you want all images to be 200px high, use this: -s ,200

If you do not use this option, imresize will not resize the image. Makes me think that the name of the program might not be that well-chosen...

-o <output-dir>

By default, imresize generates images in a ./resized directory in the working directory (creating it if it does not exist). You may want to generate images in another directory by using this command: -o ./thumbnails

Note that you can use this option to overwrite the original files.

-a <suffix>

By default, original and generated images have the same basename. However, you may want to append a suffix to the filename (just before the extension). Be sure to quote the suffix so that it is not parsed as an option, especially if you use a dash/hyphen (-): -a "-small"

-f <image-format>

By default, imresize uses the same format as the original file. You may want to use another image format. The available formats depend on what libraries you have installed, amongst those supported by PIL (Python Imaging Library): JPEG, PNG, GIF, BMP, etc. To list the image formats that are supported by your operating system, simply run without any argument.

Thus, to convert the images to PNG, use: -f PNG

-q <quality>

You can set the quality of the generated JPEG images, on a scale from 1 (worst) to 95 (best). Values above 95 should be avoided; 100 completely disables the JPEG quantization stage (from PIL documentation).

To set the quality to 80, you can thus use: -q 80

Default value is 95. Note that this option has no effect on image whose format is not JPEG.


imresize requires Python 2.4 (or above) and PIL, the Python Imaging Library. Depending on what image format you want to use, you have to install the corresponding library. See PIL documentation for further details.

imresize might work with Python 2.3 (and even prior versions) with some small adjustements.

Download and installation

Download imgresize from its SVN repository:

There is no installation process. Copy the file somewhere in your file system (most likely in your PATH) and run it. You may want to adjust the first line if python is not the proper program to run (e.g. if you want to use a specific version of Python).


imresize has been written by Damien Baty.


imresize is copyright 2007 by Damien Baty.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see the section about licenses of the GNU web site.