What are the potential benefits of creating thumbnails for images in terms of website performance?
Creating thumbnails for images can greatly improve website performance by reducing the file size of images, which in turn decreases load times and bandwidth usage. Thumbnails also help in optimizing the layout of a webpage by providing smaller, more manageable versions of images that can be easily displayed in grids or galleries.
<?php
// Create a thumbnail image from an existing image
function createThumbnail($source, $destination, $width, $height) {
$sourceImg = imagecreatefromjpeg($source);
$thumbImg = imagecreatetruecolor($width, $height);
imagecopyresampled($thumbImg, $sourceImg, 0, 0, 0, 0, $width, $height, imagesx($sourceImg), imagesy($sourceImg));
imagejpeg($thumbImg, $destination);
}
?>