English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP getimagesizefromstring() function usage and example

PHP Image Processing

getimagesizefromstring — Get image size information from a string.

Syntax

array getimagesizefromstring ( string $imagedata[, array &$imageinfo ] )

Same getimagesize() Function. The difference is that getimagesizefromstring() takes the string representation of image data as the first parameter, not the filename.

Parameter

  • imagedata:String representation of image data.

  • imageinfo:See getimagesize() Function.

Example

<?php
$img = 'w3codebox-logo.png';
// Open in file format
$size_info1 = getimagesize($img);
// Open in string format
$data = file_get_contents($img);
$size_info2 = getimagesizefromstring($data);
print_r($size_info2);
?>

The output result of the above example is:

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

PHP Image Processing