Skip to content
PHP Logo

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

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

php
$image_path = 'image.jpg';
$image_info = getimagesize($image_path);
$image_width = $image_info[0];
$image_height = $image_info[1];

echo "Image width: " . $image_width . "px<br>";
echo "Image height: " . $image_height . "px";