update page now
Laravel Live Japan

getimagesizefromstring

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

getimagesizefromstringGet 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

Example #1 getimagesizefromstring() example

<?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

add a note

User Contributed Notes 2 notes

up
23
imageman
11 years ago
getimagesizefromstring function for < 5.4

<?php
   if (!function_exists('getimagesizefromstring')) {
      function getimagesizefromstring($string_data)
      {
         $uri = 'data://application/octet-stream;base64,'  . base64_encode($string_data);
         return getimagesize($uri);
      }
}
?>
up
8
sarah at anigel dot net
11 years ago
Just a quick comment on the solution by imageman for versions < 5.4 you will need to enable allow_url_fopen in order to use the data wrapper.
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant