What is the function to change the compression of a JPEG file in PHP using GD?
To change the compression of a JPEG file in PHP using GD, you can use the `imagejpeg()` function with an optional parameter for the quality level. The quality level ranges from 0 to 100, with 0 being the lowest quality and smallest file size, and 100 being the highest quality and largest file size. By adjusting this parameter, you can control the compression level of the JPEG file.
// Load the JPEG file
$image = imagecreatefromjpeg('input.jpg');
// Set the compression quality level (0-100)
$quality = 70;
// Save the JPEG file with the new compression level
imagejpeg($image, 'output.jpg', $quality);
// Free up memory
imagedestroy($image);
Related Questions
- How can PHP developers effectively utilize Google and online resources to find solutions for common tasks like searching through directories and files?
- What security measures should be implemented to protect dynamically loaded content in PHP?
- How can PHP be used to secure a search function against potential abuse like XSS?