How can the getimagesize() function be used to determine the dimensions of an externally linked image in PHP?

To determine the dimensions of an externally linked image in PHP, you can use the getimagesize() function. This function retrieves the size of a given image file and returns an array containing the width and height of the image. You can use this function by passing the URL of the externally linked image as a parameter.

$image_url = 'https://example.com/image.jpg';
$image_size = getimagesize($image_url);

if($image_size){
    $width = $image_size[0];
    $height = $image_size[1];
    
    echo "Width: $width, Height: $height";
} else {
    echo "Unable to get image size.";
}