What potential pitfalls should be considered when creating thumbnails in PHP to avoid drastic quality loss?

When creating thumbnails in PHP, one potential pitfall to consider is the loss of image quality due to compression. To avoid drastic quality loss, it is important to set the compression quality parameter appropriately when generating thumbnails. This parameter controls the level of compression applied to the image, with a higher value resulting in better quality but larger file size.

// Create a thumbnail with appropriate compression quality
$sourceImage = imagecreatefromjpeg('original.jpg');
$thumbnail = imagecreatetruecolor(100, 100);

imagecopyresampled($thumbnail, $sourceImage, 0, 0, 0, 0, 100, 100, imagesx($sourceImage), imagesy($sourceImage));

imagejpeg($thumbnail, 'thumbnail.jpg', 90); // Set compression quality to 90

imagedestroy($sourceImage);
imagedestroy($thumbnail);