Get the size of an image using a PHP function

Get the size of an image using a PHP function

PHP provides a function to get the width and height of an image.
getimagesize()
Get the size of an image.
Description
The getimagesize() function will determine the size of any supported given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type.
getimagesize() can also return some more information in imageinfo parameter.

Example:
This is a sample code, change img_name to your image name and see result!

When you run this script the result you will see like this

Image width 379
Image height 344
Image type 2
Image attribute width=”379″ height=”344″

You will get the width, height, type of an image and also attribute of an image, I use this function in my image upload form.
Type of an image you can see from table below.

Type of Image

1 = GIF 5 = PSD 9 = JPC 13 = SWC
2 = JPG 6 = BMP 10 = JP2 14 = IFF
3 = PNG 7 = TIFF(intel byte order) 11 = JPX 15 = WBMP
4 = SWF 8 = TIFF(motorola byte order) 12 = JB2 16 = XBM

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *