What are potential pitfalls when trying to determine the size of a remote image in PHP?

When trying to determine the size of a remote image in PHP, a potential pitfall is that the file may not exist or the URL may be incorrect, leading to errors or unexpected results. To solve this issue, you can use PHP's getimagesize() function to get the image dimensions. This function returns an array with the image width and height, allowing you to handle any errors or exceptions that may occur.

$url = 'https://example.com/image.jpg';

// Get image size
$size = @getimagesize($url);

if ($size) {
    $width = $size[0];
    $height = $size[1];
    
    echo "Image width: $width, height: $height";
} else {
    echo "Failed to get image size";
}