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
<?
//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:
<?
//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 learned something with this tutorial. If you have any questions or comments at all, feel free to post them in the forums.
Automatically Get Width & Height of An Image or FlashIf 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
<?
//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:
<?
//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 learned something with this tutorial. If you have any questions or comments at all, feel free to post them in the forums.
Automatically Get Width & Height of An Image or FlashIf 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
<?
//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:
<?
//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 learned something with this tutorial. If you have any questions or comments at all, feel free to post them in the forums.
Automatically Get Width & Height of An Image or FlashIf 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
<?
//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:
<?
//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 learned something with this tutorial. If you have any questions or comments at all, feel free to post them in the forums.
<?//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 heightecho "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:
<?
//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 learned something with this tutorial. If you have any questions or comments at all, feel free to post them in the forums.
" />