Covid-19 Coronavirus Live stats and updates

Get image width and height in PHP

Get image width and height in PHP

In this quick tutorial, i am going to show you a simple way to get image width and height in PHP using a function getimagesize().

This is a very useful function in PHP, it provides function to get the width and height of an image. The getimagesize() function will determine the size of image file including flash file(swf).

Syntax

list($width, $height, $type, $attr) = getimagesize("image_name.jpg");

All you need is the URL of an image or location to any image, then you can find the dimensions of an image like this:

Code

<?php

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

echo "Image width: " . $width;
echo "<br>";
echo "Image height: " . $height;
echo "<br>";
echo "Image type: " . $type;
echo "<br>";
echo "Attribute: " . $attr;

?>

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

Result

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

For 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

Functions Used

Reference URL