Automatically Get Width & Height Of An Image
If you are working with file uploads, or if you simply need the width and height of an image/flash file, then this magical function in PHP is a must use: getimagesize
If you require to get the width and height of a image or flash file, or your working with file uploads,then this is your PHP script you want to use which the function we are going to use is : Getimagesize
PHP Code:
<?
//Here's our file. It's a flash animation with the name of animation.swf
$file = "Files/animation.swf";
//To get the height and width automatically, we use the "getimagesize" function built into PHP
//We use the list function to get the width and height values from the getimagesize function. Width goes first, height second.
list($width, $height) = getimagesize($file);
//Display the width and height
echo "Width = $width and Height = $height";
?>
This very useful function can be used to make very simple uploaders. It also can be used to dynamically resize images. Here's how we'll resize an image to half of its size, no matter what the size is:
PHP Code:
<?
//Our image file. (It could be a flash file if you wanted, but for this example, we'll use an image)
$file = "Images/Big/20303991/image.jpg";
//Get width and height of the image.
list($width, $height) = getimagesize($file);
//Now make the width and height half their values
$width = $width/2;
$height = $height/2;
//Now display the image
echo "<img src='$file' width='$width' height='$height' />";
?>
I hope you've learnt something from this