What other functions or methods should be used in conjunction with imagejpeg() for image processing in PHP?
When working with image processing in PHP using the imagejpeg() function, it is often useful to utilize other functions or methods to manipulate the image before saving it as a JPEG file. Some common functions to use in conjunction with imagejpeg() include imagecreatefromjpeg() to create an image resource from a JPEG file, imagecopyresized() to resize the image, and imagefilter() to apply filters such as grayscale or brightness adjustments.
// Example of using imagecreatefromjpeg(), imagecopyresized(), and imagejpeg() together
$source = 'example.jpg';
$destination = 'output.jpg';
// Create an image resource from the JPEG file
$image = imagecreatefromjpeg($source);
// Resize the image to 200x200 pixels
$width = 200;
$height = 200;
$resizedImage = imagecreatetruecolor($width, $height);
imagecopyresized($resizedImage, $image, 0, 0, 0, 0, $width, $height, imagesx($image), imagesy($image));
// Save the resized image as a JPEG file
imagejpeg($resizedImage, $destination);
// Free up memory
imagedestroy($image);
imagedestroy($resizedImage);