How can beginners in PHP ensure they are using the imagejpeg() function correctly?
When using the imagejpeg() function in PHP, beginners should ensure they are providing the correct parameters to the function. The first parameter should be the image resource returned by functions like imagecreatefromjpeg(), and the second parameter should be the path where the JPEG image will be saved. Beginners should also make sure that the path is writable by the web server.
// Example of using imagejpeg() function correctly
$source = imagecreatefromjpeg('example.jpg');
$destination = 'output.jpg';
// Save the image as a JPEG file
imagejpeg($source, $destination);
// Free up memory
imagedestroy($source);