imagegd2 


gd apg

CREATE a particular GD2 image to be shown in a browser or stored in a file.





This function allows to output truecolor images.


The GD and GD2 image formats are proprietary image formats of libgd.

They have to be regarded obsolete, and should only be used for development and testing purposes.






As of PHP 8.0.3 it is possible to set $file = NULL.

However, if libgd fail to output the image, this function returns TRUE.

This function returns TRUE on success os FALSE on failure.


The GD2 format is commonly used to allow fast loading of parts of images.

Note that the GD2 format is only usable in GD2-compatible applications.



<?php

bool imagegd2
(  GdImage $image, ?string $file null,
                                                              
int $chunk_size 128,
                                                              
int $mode IMG_GD2_RAW
)


where,

$image The image identifier

$file 
The path or stream resource

$chunk_size 
The chunk size

$mode 
The type mode
              
SEE the below TABLE )

?>

  $image   


The image identifier.



  $file   


The path or stream resource which is automatically being closed after this function returns to save the file to.



  $chunk_size   


The chunk size.



  $mode   


The type mode constant.

IMAGE GD2 TYPE CONSTANTS
CONSTANT VALUE MEANING DEFAULT
IMG_GD2_RAW 1 RAW format IMG_GD2_RAW
IMG_GD2_COMPRESSED 2 Compressed format
ed48


  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$im01 imagecreate (200200);
$blue imagecolorallocate($im01008);

$img_file_name 'gd2/GD2 001 01.gd2';

$bool01 imagegd2($im01$img_file_name);

if (
$bool01 == TRUE)
{
$mess01 'The image was created, however,
         <br>CAN NOT BE DISPLAYED by this browser!'
;
echo 
'$bool01 = ';
var_dump($bool01);
echo 
'<br><br>' $mess01;
imagedestroy($im01);
}
else
{
$mess01 'The image COULD NOT BE CREATED!';
echo 
$mess01;
}

?> 

 RESULT   

GD2 001 01.gd2

$bool01 = bool(true)

The image was created, however,
CAN NOT BE DISPLAYED by this browser!


  2 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$im02 imagecreate (200200);
$blue imagecolorallocate($im02008);
$green imagecolorallocate($im0201270);

$img_file_name 'gd2/GD2 002 02.gd2';

$chunk_size02 108;

$type02 IMG_GD2_COMPRESSED;

$bool02 imagegd2($im02$img_file_name$chunk_size02$type02);

if (
$bool02 == TRUE)
{
$mess02 'The image was created, however,
            <br>CAN NOT BE DISPLAYED by this browser!'
;
echo 
'$bool02 = ';
var_dump($bool02);
echo 
'<br><br>' $mess02;
imagedestroy($im02);
}
else
{
$mess02 'The image COULD NOT BE CREATED!';
echo 
$mess02;
}

?> 

 RESULT   

GD2 002 02.gd2

$bool02 = bool(true)

The image was created, however,
CAN NOT BE DISPLAYED by this browser!


  3 EXERCISE   

<?php

// Try this code

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$im03 imagecreatetruecolor (200200);
$blue imagecolorallocate($im03008);
$green imagecolorallocate($im0301270);

$img_file_name NULL;

$chunk_size03 108;

$type03 IMG_GD2_COMPRESSED;

$bool03 imagegd2($im03$img_file_name$chunk_size03$type03);

if (
$bool03 == TRUE)
{
$mess03 'The image was created, however,
         <br>CAN NOT BE DISPLAYED by this browser!'
;
echo 
'<br><br>$bool03 = ';
var_dump($bool03);
echo 
'<br><br>' $mess03;
imagedestroy($im03);
}
else
{
$mess03 'The image COULD NOT BE CREATED!';
echo 
$mess03;
}

?>