Join Michael as he demonstrates how PHP, along with the GD library, can create thumbnails of all your images.
By : Michael Bailey
Depending upon how it's done, displaying a page of thumbnail images can be very cumbersome. Allowing the browser to resize images requires the client browser to download the entire, full-size image, then clumsily resize the image to a specified size. This causes the page to load very slowly and creates unavoidable distortion in the resulting images. The other option is to make separate thumbnail images for each individual image. This is fine if you only plan to display a few images, but becomes unrealistic on a large scale or a site involving dynamic images. Fortunately there are ways around these problems using the GD library in PHP.
This tutorial will outline how to write a PHP script to create thumbnail images on the fly. Since this requires the GD library, you will need an installation of PHP with at least GD 2.0.1 enabled (you can use older versions with a slight change which I will explain).
The script we will be writing receives one parameter on the query string which corresponds to the relative path of the full-size image. This address is to be placed as the src field of an image tag. An example image tag might look like this: <img src="/thumbnail.php?dir/image.png">. With no further ado let us procede to the source code.