getimagesizefromstring()

getimagesizefromstring() — Get the size of an image from a string.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.4.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

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

Signature

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

Parameters

ParameterTypeWhat it takes
$stringstringThe image data, as a string.
&$image_infoarraySee getimagesize().

Return value

See getimagesize().

Example

A runnable snippet:

$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

getimagesize()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page getimagesizefromstring() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.