getimagesizefromstring 


php apg

GET the size of an image from a string.





PALETTE IMAGE

is the designation term for images with a small number of colors.

For this type of image, a maximum of 256 colors are accepted.


TRUECOLOR IMAGE

is the designation term for images with a great number of colors.

For this type of image, a maximum of 16,777,216 colors are accepted.





This function does not require the GD image library.

Included in this section for being in common use.


This function returns, directly, the size of any supported given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type.

Additionally can also return some more information in $image_info parameter passed as reference.

This function expects $string to be a valid string image file.

If a non-image file is supplied, it may be incorrectly detected as an image and the function will return successfully, but the array may contain nonsensical values.

You should not use this function to check that a given file is a valid image; there are other functions to do this.

This function is identical to getimagesize except that accepts a string instead of a file name as the first parameter.

STREAM WRAPPERS MEANING
file:// LOCAL File System
http:// URL HTTP
ftp:// URL FTP
php:// I/O streams
zlib:// Data Compression stream
data:// DATA (RFC-2397)
glob:// Find Filenames
phar:// PHP Archive
ssh2:// Secure Shell 2
rar:// RAR
ogg:// Audio
expect:// Interaction of stream processes
ed48


$image_info is the optional parameter that allows to extract some extended information from the image file.

There are other functions which display such information in more detail, if available, in JPEG files.



<?php

array|false getimagesizefromstringstring $string, array &$image_info null )

where,

$string The image data as string

&$image_info The extended information 
                                        from the image string file
                       
PASSED as reference )

?>

  $string   


The image data as string.



  &$image_info   


The metadata elements, if they exist in the tested image string file.

Passed as reference.



  1 EXERCISE   

<?php

$img 
'png/PNG 006 01.png';

echo 
'<img src="' $img '" title="Gago&Sacadura(PT).png"><br><br>';

$i1 getimagesize($img);

print_r($i1);
echo 
'<br><br>'

$data file_get_contents($img);

$i2 getimagesizefromstring($data);

echo 
$data '<br><br><br>';

/* - - - - - - - - - - - - - - - - - - - - - - - -
   uncomment the previous line to see the result
   - - - - - - - - - - - - - - - - - - - - - - - - */ 

print_r($i2);


?>

 RESULT   

PNG 006 01.png

Exiting Image

apr


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


  2 EXERCISE   

<?php 
  
$img 
'ico/ICO 001 03.ico';

echo 
'<img src="' $img '" title="ICO 001 03.ico" width="32"><br><br>';
   
// Open image as a string 
$data file_get_contents($img); 

/// echo $data . '<br><br>';

/* - - - - - - - - - - - - - - - - - - - - - - - - 
   uncomment the previous line to see the result
   - - - - - - - - - - - - - - - - - - - - - - - - */ 
   
// getimagesizefromstring function 
// accepts image data as string 
$info getimagesizefromstring($data); 
  
// Display the image content 
print_r($info);
 
?> 

 RESULT   

ICO 001 03.ico

apr

Array
(
[0] => 16
[1] => 16
[2] => 17
[3] => width="16" height="16"
[bits] => 32
[mime] => image/vnd.microsoft.icon
)