Skip to content

Get image height and width PHP ?

Last updated on January 17, 2018

We can easily extract image information from the Image URL using PHP’s predefined function called getimagesize()

I Use this function whenever I need to know image HEIGHT and WIDTH, this function returns an array with 5 items, first, two are image Height and width, 3rd one is image type(png/jpg…etc, ) find more image types list below.. etc

 // get width and height 
 list($width, $height) = getimagesize($filename);
or 
$data = getimagesize($filename);
$width = $data[0];
$height= $data[1];

We can use this function to get image height and width while uploading images


 list($width, $height) = getimagesize($_FILES['upload']['tmp_name']);

 

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
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments