How can the discrepancy in file size between the original image and the downloaded image be addressed when saving images to the hard drive in PHP?

When saving images to the hard drive in PHP, the discrepancy in file size between the original image and the downloaded image can be addressed by compressing the image before saving it. This can be done using PHP's image manipulation functions to reduce the file size without significantly impacting the image quality.

// Load the original image
$original_image = imagecreatefromjpeg('original.jpg');

// Compress the image by setting the quality parameter
imagejpeg($original_image, 'compressed.jpg', 80); // 80 is the quality parameter (0-100)

// Free up memory
imagedestroy($original_image);