getimagesize()

Summary

Learning the PHP function getimagesize(). Not only does this function get the size of an image, it gets the info of the file and of Flash files.

I used this function to set the layout of the images and Flash files on my portfolio site.

Example

UCD CoHo Calendar Poster
The information of this image are as follows:
width (index 0) is: 585
height (index 1) is: 435
image type (index 2) is: 3
text of w/h (index 3) is: width="585" height="435"
mime (index 'mime') is: image/png
channels (index 'channels') is:
bits (index 'bits') is: 8

Date Created

3 Nov 2008.

Help

  1. PHP: getimagesize.
  2. PHP: exif_imagetype defines the values of the image type.

Process

Really simple. Just tested the function by listing all the items in the array.

  1. List of the values corresponding with the index numbers.

The Code

Here’s the code. Please link back here if you’re using it.

Put this PHP in the body tag, where you want the text to appear.


$size=getimagesize("http://www.ivanwlam.com/flash/index/080207-screen.swf");
echo "width (index 0) is: $size[0] <br />";
echo "height (index 1) is: $size[1] <br />";
echo "image type (index 2) is: $size[2]<br />";
echo "text of w/h (index 3) is: $size[3] <br />";
echo "mime (index 'mime') is: $size[mime] <br />";
echo "channels (index 'channels') is: $size[channels] <br />";
echo "bits (index 'bits') is: $size[bits] <br />";
            

Return to top