What are common reasons for errors when using the imagejpeg function in PHP?

Common reasons for errors when using the imagejpeg function in PHP include incorrect file paths, insufficient permissions on the target directory, or unsupported image formats. To solve these issues, ensure that the file path is correct, the target directory has proper write permissions, and the image format is supported by the function.

// Check if the imagejpeg function executed successfully
if (imagejpeg($image, 'output.jpg')) {
    echo 'Image saved successfully.';
} else {
    echo 'Error saving image.';
}