PHP

PHP Get Image Dimensions (Width & Height) Examples

Have you ever wanted to get image dimensions  using PHP? In this article, I am going to share an easy way to use PHP to get image dimensions (width & height).

Examples in PHP to Get Image Dimensions (Width & Height)

Following is the complete HTML + PHP source code that shows how to get the image dimensions (width & height) when the page is loaded:

Example: Get image width & height (dimensions) using PHP

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Get Image Dimensions</title>
</head>

<body>

<?php

list($width, $height) = getimagesize("images/banner.png");

echo "Width: " .$width." Height: " .$height;

?>

</body>
</html>

When the above code is executed, the page will echo the width and height of the image.

That’s it!

Do you know of any other ways to find image width and height using PHP? Feel free to share by commenting below.

One Comment on PHP Get Image Dimensions (Width & Height) Examples

  1. 1

    I have thought about it for some time. How can I edit my image in PHP. Thank you for sharing the post. It helps me a lot.

Share your thoughts, comment below now!

*

*