Category Archives: How to get the height and widht of File(Image)

Get the width and height of an image using a function in PHP

PHP provides a function getimagesize(). This function helps to find the image height,widht, type and attribute.

Here is the sample code:

<?php

if(isset($_POST['submit'])){  // code executes on submit event

list($width, $height, $typeOfFile, $attribute) = getimagesize('$_FILES['imagename']['tmp_name']');
 //<input type='file' name='imagename'

echo $width;  //output:300

echo $height; //output:400

echo $typeOfFile; //Output:2

echo $attribute;  //output: <strong>width="300" height="400"</strong>

}

?&gt;

NOTE:

Type of the 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