• How to get image details using a function in PHP

    There is an inbuilt function in PHP that provides functionality to get the width and height of an image.
    The getimagesize() function can determine the size of image file including flash file (swf).

    Syntax of function:
    list($width, $height, $type, $attr) = getimagesize(“image_name.jpg”);

    Demo Code:
    Below is a sample code to demonstate the getimagesize() function.
    change imageName to your image name to test it.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    <?php
     
    list($width, $height, $type, $attr) = getimagesize("image_name.jpg");
     
     
    echo "Image width " .$width;
    echo "<BR>";
    echo "Image height " .$height;
    echo "<BR>";
    echo "Image type " .$type;
    echo "<BR>";
    echo "Attribute " .$attr;
     
    ?>

    When you will run this script you will see the result like this

    Image width 400
    Image height 500
    Image type 3
    Image attribute width=”400″ height=”500″

    You will get the width, height, type of an image and also attribute of an image. It can be used in my image upload form.
    Type of an image you can see from table below.

    Type of Image:

    1 = GIF
    2 = JPG
    3 = PNG
    4 = SWF
    5 = PSD
    6 = BMP
    7 = TIFF(intel byte order)
    8 = TIFF(motorola byte order)
    9 = JPC
    10 = JP2
    11 = JPX
    12 = JB2
    13 = SWC
    14 = IFF
    15 = WBMP
    16 = XBM

Comments on this post

Leave a Reply

  • Security Code :


    + five = 8