CancelImage Upload

How to find out the height and width of an image using PHP

The following page will discuss how to load an image's size details into an array. These details can come in handy with functions to create thumbnail versions of an image, or simply to specify an image's exact dimensions inside an image tag.

To load the details of an image into an array we will make use of the following function:

$imageDetails = getimagesize("path/file.jpg");

The height and width of the image file.jpg would be loaded as an array into the variable $imageDetails, and could be accessed as displayed in the code below:

echo "Image Width: ".$imageDetails[0]."px";

echo "<br>";

echo "Image Height: ". $imageDetails[1]."px";

Here then is a more extensive example:

<?php

$path = "images/file.jpg";

if(file_exists($path))
{

       $imageDetails = getimagesize($path);

       echo "Image Width: ".$imageDetails[0]."px";

       echo "<br>";

       echo "Image Height: ". $imageDetails[1]."px";

}
else
{

       echo "Image does not exist!";

}

?>


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com