How can PHP developers work around server restrictions on external URL file access when using imagefilter?

PHP developers can work around server restrictions on external URL file access when using imagefilter by downloading the image from the external URL using cURL or file_get_contents, saving it to a temporary file on the server, and then applying the imagefilter function to the local file.

$url = 'https://example.com/image.jpg';
$tempFile = tempnam(sys_get_temp_dir(), 'image');
file_put_contents($tempFile, file_get_contents($url));

$image = imagecreatefromjpeg($tempFile);
if ($image) {
    imagefilter($image, IMG_FILTER_GRAYSCALE);
    imagejpeg($image, 'output.jpg');
    imagedestroy($image);
}

unlink($tempFile);