<?php
	function makeThumbnail($source, $destination, $width, $height)
	{
		//load source image
		if(!($sourceImage = @imagecreatefromjpeg($source)))
		{
			//error, so create an error image and exit
			$image = imagecreate($width, $height);
			$colorWhite = imagecolorallocate($image,
				255, 255, 255);
			$colorBlack = imagecolorallocate($image, 0, 0, 0);
			imagefill($image, 0, 0, $colorWhite);
			imagestring($image, 1, 1, 10, "Failed!", $colorBlack);
			imagepng($image, $destination);
			return(FALSE);
		}

		//make destination
		$destinationImage = imagecreatetruecolor($width, $height);

		//copy source into destination,
		//resampling and possibly distorting
		imagecopyresampled($destinationImage, $sourceImage,
			0, 0, 0, 0, $width, $height,
		imagesx($sourceImage), imagesy($sourceImage));

		//save image
		imagepng($destinationImage, $destination);
	}

	makeThumbnail("waterfall.jpg", "waterfall_thumb.jpg", 64, 64);
?>
<h1>Original</h1>
<img src="waterfall.jpg" border="0">
<h1>Thumbnail</h1>
<img src="waterfall_thumb.jpg" border="0">