Thumbnail Maker

Based on the tutorial How to create a gallery of thumbnail images on this site, the PHP script Thumbnail Maker provides a ready-to-use program that is applied to an image file or a whole directory, according to the arguments of the command.

Since the 1.2 version, this is also a conversion tool.

Features of the script

The script resizes an image or creates a thumbnail, and it applies to one file or all images in a directory according to:

- the height passed in parameter,
- or the width,
- or both the height and width.

In the latter case images are resized retaining the original proportions and possibly centered and trimmed to obtain the necessary dimensions, which is essential to create a gallery of uniform thumbnails.

Command and options

The syntax is:

php resizer.php [options] (image-file | path | *)

The options are the dimensions of the new image and optionally a new format.

We must interpret the command like this:

Resize depending on the options and ...

- the name of an image file,
- or the path to the content of a folder containing images,
- or with * the images in the current directory.

Dimensions options

In case one wants to simply resize the image, a single option is passed for the new height or width.



The new image has a width of 100 pixels, the height will be adjusted to maintain proportions.


The new image will have a height of 100 pixels, and the width will be adapted.

-w100 -h100

The thumbnail will have a height and a width of 100 pixels. The proportions will be preserved, but the image will be centered and cropped at borders. The tutorial explains in detail the procedure and shows the PHP code that performs this processing.

If not parameter of dimension are given, the default settings (150 x 150) will be used.

Conversion options

It is possible to change the format of the thumbnail, or to use the script as a converting tool without to change its dimensions.

Supported formats are:

-g     convert to gif.
-p     convert to png.
-j      convert to jpg.


php resizer.php -j myimage.png 

When a new format is given, and no dimension option passed, the original dimensions of the image are preserved, while when no format is given nor dimension, the default thumbnail size is used instead.

Thus in the example, the image is converted to JPG and its dimensions preserved.


Download the Thumbnail Maker archive

The script resizer.php is licensed under the GNU General Public License 2.0.
Use this script freely but keep the copyright notice in the source code.