get image width and height using PHP

Sometime we have to get the uploaded image name from database. But we don’t know the image width and height. Width and height may be variable. But we want to know the actual width and height of an image. We can use getimagesize() PHP function to get the width and height of an image.

array getimagesize ( string $filename [, array &$imageinfo ] )

This function returns an array of 7 elements. Index 0 and 1 contains respectively the width and the height of the image.

Example:

<?php

$image_Name = ‘ekram.jpg’;

list($width, $height) = getimagesize($image_Name);

echo “<img src=’$image_Name’ width=’$width’ height=’$height’ />”;

?>

2 thoughts on “get image width and height using PHP

  1. Haider

    Hey very very thanks for telling it ….. really I am searching for anything else but I also want this and I found it here very very thanks…. I used this at on my web

Leave a Reply

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