The getimagesizefromstring() function is an inbuilt function in PHP which is used to get the size of an image from a string. This function accepts the image data as a string parameter and determines the image size and returns the dimensions with the file type and height/width of the image.
Syntax:
array getimagesizefromstring( $imagedata, &$imageinfo )
Parameters: This function accepts two parameters as mentioned above and described below:
- $filename: It is a mandatory parameter which accepts image data as a string.
- $imageinfo: It is an optional parameter which allows to extract some extended information from the image file such as the different JPG APP markers as associative array.
Return Value: This function returns the dimensions along with the file type and the height/width text string.
Below programs illustrate the getimagesizefromstring() function in PHP:
Image:

Example 1 :
<?php $img = // Open image as a string $data = file_get_contents($img); // getimagesizefromstring function accepts image data as string $info = getimagesizefromstring($data); // Display the image content var_dump($info); ?> |
Output:
array(6) {
[0]=> int(667)
[1]=> int(184)
[2]=> int(3)
[3]=> string(24) "width="667" height="184""
["bits"]=> int(8)
["mime"]=> string(9) "image/png"
}
Example 2:
<?php $img = // Open image as a string $data = file_get_contents($img); // getimagesizefromstring function accepts image data as string list($width, $height, $type, $attr) = getimagesizefromstring($data); // Displaying dimensions of the image echo "Width of image: " . $width . "<br>"; echo "Height of image: " . $height . "<br>"; echo "Image type: " . $type . "<br>"; echo "Image attribute: " . $attr; ?> |
Output:
Width of image: 667 Height of image: 184 Image type: 3 Image attribute: width="667" height="184"
Reference: http://php.net/manual/en/function.getimagesizefromstring.php
Recommended Posts:
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

