How to get image height and width dynamically using PHP?

Hello friends,

In last week while performing my task I had a requirement to get image height and width dynamically with PHP programming. To satisfy that requirement I had searched the web and found the optimum way to do so, that I want to discuss here.

PHP provides an inbuilt function named getimagesize() to get the size of an image.

The getimagesize() function accepts one argument i.e. image path and returns an array with 7 elements.


array getimagesize (string $filepath)

The returning array consist dimensions of given image file along with the file type.

Index 0 and 1 indicates the width and height of the image respectively.

Index 2 is the constant indicating the type of the image.

Index 3 is a text string with the height=”yyyy” width=”xxxx” string.

The last argument mime is the correspondent MIME type of an image.

Hope this will help you.

Thanks.

Speak Your Mind

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: