Google trends Public Holidays Coupon Code Code Compiler

Get image width and height using php


Dec 1, 2023

Get image width and height using php

Learn easy and quick way to find image width and Hight using php inbuilt function.

In this tutorial, i am going to show you a easy way to get image height and width in PHP using getimagesize() function. getimagesize() is a inbuilt function in the php.
This is a very useful function in PHP to get hight and width of an image. The getimagesize() function will determine the size of image file.

Syntex


list($width, $height, $type, $attr) = getimagesize("path/image.jpg");

Let’s see an example of getting dimensions of an image
All you need is the path of an image or location to any of the image, then you can find the dimensions of an image like below:

Code


<?php
 
list($width, $height, $type, $attr) = getimagesize("path/image.jpg");
 
echo "Image width: " . $width;
echo "
"; echo "Image height: " . $height; echo "
"; echo "Image type: " . $type; echo "
"; echo "Attribute: " . $attr; ?>

Result

Image width: 379
Image height: 344
Image type: 2
Image Attribute: width=”379″ height=”344″

 

For Type of image

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

Copyright 2024. All rights are reserved