What is the relationship between image compression and the quality parameter in imagejpeg in PHP?
When using the imagejpeg function in PHP to save a JPEG image, the quality parameter determines the level of compression applied to the image. A higher quality value will result in a larger file size and better image quality, while a lower quality value will result in a smaller file size but lower image quality. It is important to find a balance between file size and image quality when setting the quality parameter.
// Example of setting the quality parameter in imagejpeg function
$source_image = imagecreatefromjpeg('input.jpg');
$output_image = 'output.jpg';
// Set the quality parameter (0 - 100)
$quality = 80;
// Save the image with the specified quality
imagejpeg($source_image, $output_image, $quality);
// Free up memory
imagedestroy($source_image);