Search code examples
phpimagegetimagesize

what does PHP.getimagesize actually return


The PHP manual says that it returns up to 7 elements. and says 0, 1 are width and height followed by image type and attribute. Then it goes on to give the an example so

$size=getimagesize()

So, what does it return ? An array of 7 elements or just one ? Or is it auto-magical ? Actually I want the width, height, type and size.


Solution

  • You'll get image height, width and type from getimagesize() but for size, you can use filesize() function. Please check below example -

    //Get image information
    $getImageInfo = getimagesize("123.png");
    print_r($getImageInfo);
    //Get image size information
    echo filesize("123.png");
    

    Output

    Array ( [0] => 657 [1] => 543 [2] => 3 [3] => width="657" height="543" [bits] => 8 [mime] => image/png ) 254387

    Please make it correct answer, if this is useful.