What is the function in PHP to get the height and width of an image stored in a variable?

To get the height and width of an image stored in a variable in PHP, you can use the getimagesize() function. This function returns an array containing the dimensions of the image (width and height) as well as other information like image type and attribute. By using getimagesize() on the image variable, you can easily retrieve the height and width values for further processing in your code.

$image = file_get_contents('image.jpg');
$image_dimensions = getimagesizefromstring($image);
$image_width = $image_dimensions[0];
$image_height = $image_dimensions[1];

echo "Image Width: " . $image_width . "<br>";
echo "Image Height: " . $image_height;