What function in PHP can be used to retrieve the width and height of an image?

To retrieve the width and height of an image in PHP, you can use the getimagesize() function. This function returns an array containing the width and height of the image, as well as other information like image type and attributes. By using this function, you can easily retrieve the dimensions of an image and use them in your PHP code.

$image = 'image.jpg';
$dimensions = getimagesize($image);
$width = $dimensions[0];
$height = $dimensions[1];

echo "Width: " . $width . "px<br>";
echo "Height: " . $height . "px";