getimagesize 


php apg

GET physical information about image files.





This function returns the physical information about image files which is created by imagecreate or imagecreatetruecolor for example.


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 $filename to be a valid 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.

Some image files like JPC and JP2 are capable of having components with different bit depths.

In this case, the value for bits is the highest bit depth encountered.

Also, JP2 files may contain multiple JPEG 2000 codestreams.

In this case, this function returns the values for the first codestream it encounters in the root of the file.

The information about icons are retrieved from the icon with the highest bitrate.

In the GIF images with one or more frames, where each frame may only occupy part of the image; the size reported by this function is the overal size, that is readed by the logical screen descriptor.

$filename can reference a local file or, (configuration permitting), a remote file using one of the supported stream wrappers:

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 getimagesizestring $filename, array &$image_info null )

where,

$filename The file to retrieve information about

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

?>

  $filename   


The path to the image file.



  &$image_info   


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

Passed as reference.



  1 EXERCISE   

<?php

$tst_img 
=  "jpeg/JPEG 001 01.jpg";

echo 
$tst_img?>

<br><br><img src="<?php echo $tst_img?>
  alt="<?php echo $tst_img?>"><br><br><br>

<?php

$get_info01 
getimagesize($tst_img);

echo 
'<pre>';
var_dump($get_info01);
echo 
'</pre><br>';

?>

 RESULT   

JPEG 001 01.jpg

Existing Image

JPEG 001 01.jpg apr

array(7) {
[0]=>
int(300)
[1]=>
int(300)
[2]=>
int(2)
[3]=>
string(24) "width="300" height="300""
["bits"]=>
int(8)
["channels"]=>
int(3)
["mime"]=>
string(10) "image/jpeg"
}


  2 EXERCISE   

<?php


$tst_img 
"jpeg/JPEG 002 02.jpg";

echo 
$tst_img?>

<br><br><img src="<?php echo $tst_img?>
 alt="<?php echo $tst_img?>"><br><br>

<?php

$get_info02 
getimagesize($tst_img$arr_info);


print_r($arr_info);

echo 
'<pre>';
var_dump($get_info02);
echo 
'</pre>';

?>

 RESULT   

JPEG 002 02.jpg

Existing Image

JPEG 002 02.jpg apr

Array ( [APP0] => JFIF`` )

array(7) {
[0]=>
int(300)
[1]=>
int(300)
[2]=>
int(2)
[3]=>
string(24) "width="300" height="300""
["bits"]=>
int(8)
["channels"]=>
int(3)
["mime"]=>
string(10) "image/jpeg"
}


  3 EXERCISE   

<?php

$tst_ico_img 
"ico/ICO 001 03.ico";

echo 
$tst_ico_img?>

<br><br><img src="<?php echo $tst_ico_img?>
 alt="<?php echo $tst_ico_img?>" width="32"><br><br>

<?php

$get_ico_info 
getimagesize($tst_ico_img$arr_ico_info);

echo 
'<pre>';
print_r($get_ico_info);
echo 
'</pre>';

if(
count($arr_ico_info) != 0)
{
echo 
'<pre>';
print_r($arr_ico_info);
echo 
'</pre>';
}
else
{
echo 
'No one extended information is available!';
}

?>

 RESULT   

ICO 001 03.ico

Existing Image

ICO 001 03.ico apr

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


No one extended information is available!

  4 EXERCISE   

<?php

$tst_img04 
"png/PNG 005 04.png";

echo 
$tst_img04?>

<br><br><img src="<?php echo $tst_img04?>
 alt="<?php echo $tst_img04?>" width="32"><br><br>

<?php

$get_info04 
getimagesize($tst_img04$arr_info04);


echo 
'<pre>';
print_r($get_info04);
echo 
'</pre>';

if(
count($arr_info04) != 0)
{
echo 
'<pre>';
print_r($arr_info04);
echo 
'</pre>';
}
else
{
echo 
'No one extended information is available!';
}

?>

 RESULT   

PNG 005 04.png

Existing Image

PNG 005 04.png  apr

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


No one extended information is available!

  5 EXERCISE   

<?php

$tst_img 
"image/Alcázar de Toledo(ES).jpg";

echo 
$tst_img?>

<br><br><img src="<?php echo $tst_img?>
 alt="<?php echo $tst_img?>" width="300"><br><br>

<?php

$get_info05 
getimagesize($tst_img$arr_info);


// print_r($arr_info);

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

echo '<br><br><pre>';

print_r($get_info05);

echo 
'</pre><br><br>';

?>

 RESULT   

Alcázar de Toledo(ES).jpg

Existing Image

Alcázar de Toledo(ES).jpg apr

Array
(
[0] => 640
[1] => 424
[2] => 2
[3] => width="640" height="424"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)


Copyright (c) by zerof