How can external images be loaded and displayed using PHP functions like imagecreatefromjpeg?

To load and display external images using PHP functions like imagecreatefromjpeg, you can use the file_get_contents function to retrieve the image data from a URL, and then pass that data to imagecreatefromstring to create an image resource. Finally, you can output the image using imagejpeg or other image output functions.

$url = 'https://example.com/image.jpg';
$imageData = file_get_contents($url);
$image = imagecreatefromstring($imageData);

header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);