How can the quality of resized images be controlled when using the Imagejpeg() function in PHP?
When using the Imagejpeg() function in PHP to resize images, the quality of the resized images can be controlled by setting the third parameter of the function to specify the quality level. A higher quality level will result in a larger file size but better image quality, while a lower quality level will reduce file size but may impact image clarity.
// Set the quality level for resized images
$image = imagecreatefromjpeg('original.jpg');
$width = imagesx($image);
$height = imagesy($image);
$new_width = 200;
$new_height = 150;
$resized_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($resized_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($resized_image, 'resized.jpg', 80); // 80 is the quality level (0-100)
imagedestroy($image);
imagedestroy($resized_image);