How can PHP be used to create thumbnails with a specific size, even when the original images have varying dimensions?

When creating thumbnails with PHP, you can use the `imagecopyresampled()` function to resize the original image to the desired thumbnail size while maintaining the aspect ratio. By specifying the width and height of the thumbnail, you can ensure that all thumbnails have a consistent size regardless of the dimensions of the original images.

// Specify the desired thumbnail size
$thumbWidth = 100;
$thumbHeight = 100;

// Load the original image
$originalImage = imagecreatefromjpeg('original.jpg');
$originalWidth = imagesx($originalImage);
$originalHeight = imagesy($originalImage);

// Create a new image with the specified thumbnail size
$thumbnail = imagecreatetruecolor($thumbWidth, $thumbHeight);

// Resize and copy the original image to the thumbnail
imagecopyresampled($thumbnail, $originalImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $originalWidth, $originalHeight);

// Output the thumbnail
header('Content-Type: image/jpeg');
imagejpeg($thumbnail);

// Clean up
imagedestroy($originalImage);
imagedestroy($thumbnail);