php8.5
Home/ Manual/ image / functions/ getimagesizefromstring

getimagesizefromstring

PHP function Edit on GitHub ✎

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

Get the size of an image from a string

Description

getimagesizefromstring(string $string, array $image_info = null): array|false

Identical to getimagesize() except that getimagesizefromstring() accepts a string instead of a file name as the first parameter.

See the getimagesize() documentation for details on how this function works.

Parameters

string

The image data, as a string.

image_info

See getimagesize().

Return Values

See getimagesize().

Examples

getimagesizefromstring() example

php
<?php
$img = '/path/to/test.png';

// Open as a file
$size_info1 = getimagesize($img);

// Or open as a string
$data       = file_get_contents($img);
$size_info2 = getimagesizefromstring($data);
?>

See Also

Source: reference/image/functions/getimagesizefromstring.xml · from the official PHP manual (php/doc-en)