imagegif 


gd apg

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





This function creates a GIF file in $file from the $image which is created by imagecreate or imagecreatetruecolor, for example.

The image created by this function is a PALETTE IMAGE in the format GIF87a but it can also be, as we will see later GIF89a.

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





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

This function returns TRUE on success os FALSE on failure.





Graphics Interchange Format, (GIF)

is a bitmap image format that was developed by a team at the online services provider CompuServe led by American computer scientist Steve Wilhite on June 15, 1987.

It has since come into widespread usage on the World Wide Web due to its wide support and portability between many applications and operating systems.

The format supports up to 8 bits per pixel for each image, allowing a single image to reference its own palette of up to 256 different colors chosen from the 24-bit RGB color space.

It also supports animations and allows a separate palette of up to 256 colors for each frame.

These palette limitations make GIF less suitable for reproducing color photographs and other images with color gradients, but it is well-suited for simpler images such as graphics or logos with solid areas of color.

GIF images are compressed using the Lempel–Ziv–Welch, (LZW), lossless data compression technique to reduce the file size without degrading the visual quality.

This compression technique was patented in 1985.

Controversy over the licensing agreement between the software patent holder, Unisys, and CompuServe in 1994 spurred the development of the Portable Network Graphics, (PNG), standard.

By 2004 all the relevant patents had expired.

. . . . . .

The original version of GIF was called 87a.

In 1989, CompuServe released an enhanced version, called 89a, which added support for animation delays, (multiple images in a stream were already supported in 87a), transparent background colors, and storage of application-specific metadata.

The 89a specification also supports incorporating text labels as text, (not embedding them in the graphical data), but as there is little control over display fonts, this feature is not widely used.

The two versions can be distinguished by looking at the first six bytes of the file, (the "magic number" or signature), which, when interpreted as ASCII, read "GIF87a" and "GIF89a", respectively.

. . . . . .

From Wikipedia, the free encyclopedia.



<?php

bool imagegif 
GdImage $imageresource|string|null $file null )

where,

$image The image identifier 

$file 
The path or stream resource
           
SEE the below TABLE )

?>

  $image   


The image identifier.



  $file   


The path or stream resource.

$file 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


  1 EXERCISE   

<?php

$img01 
imagecreate(150150);
// palette image
$blue imagecolorallocate($img0100255);
// the first color - to be the background color
$red imagecolorallocate($img0125500);

$img_name "gif/GIF 001 01.gif";
// normal link

var_dump($img01);

$bool01 imagegif($img01$img_name);

if (
$bool01 == true)
{
echo 
'<br><br>$bool01 = ' $bool01 
    
'<br><br>The image has been created!<br><br>';

echo 
'<img src="' $img_name 
'" alt="' $img_name '" title="' $img_name '">';
}
else
{
echo 
'<br><br>$bool01 = ' $bool01 
     
'<br><br>The image was NOT created!';
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   
    $bool01 return: 
         1 (TRUE) if the image WAS created
     or  0 (FALSE) if the image WAS NOT created
        
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

?> 

 RESULT   

GIF 001 01.gif

The image has been created!

GIF 001 01.gif apr

Note that two colors were reported in this exercise, however, only the first was used to generate the background color of the image, in this case,  blue .

This always happens when using imagecreate.

See the note in the last exercise on this same page.


  2 EXERCISE   

<?php

define 
('P2GIFNW''file://' __DIR__ '/gif/');

echo 
P2GIFNW '<br><br>';
// stream wrapper link

$img02 imagecreate(150150);
// palette image
$green imagecolorallocate($img0202550);
// the color used as backgroud
$img_name "GIF 002 02.gif";

var_dump($img02);

$bool02 imagegif($img02P2GIFNW $img_name);

if (
$bool02 == TRUE)
{
echo 
'<br><br>$bool02 = ' $bool02 
    
'<br><br>The image has been created!<br><br>';

echo 
'<img src="gif/' .  $img_name 
   
'" alt="' $img_name '" title="' $img_name '">';
}
else
{
echo 
'<br><br>$bool02 = ' $bool02 
   
'<br><br>The image was NOT created!';
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   
    $bool02 return: 
         1 (TRUE) if the image WAS created
     or  0 (FALSE) if the image WAS NOT created
     
        P2GIFNW => PATH to the image folder
        
   - - - - - - - - - - - - - - - - - - - - - - - - - - - */

?> 

 RESULT   

GIF 002 02.gif

The image has been created!

GIF 002 02.gif apr

Only one color was reported in this exercise, so that color was used to generate the background color of the image, in this case  green .

This always happens when using imagecreate.


  3 EXERCISE   

<?php

$img03 
imagecreate(150150);
// palette image
$img_name "gif/GIF 003 03.gif";
// normal link
$bool03 imagegif($img03$img_name);
// without the first color used as background

var_dump($img03);

if (
$bool03 == TRUE)
{
echo 
'<br><br>$bool03 = ' $bool03 
          
'<br><br>The image has been created!<br><br>';

echo 
'<img src="' $img_name 
   
'" alt="' $img_name '" title="' $img_name '">';
}
else
{
echo 
'<br><br>$bool03 = ' $bool03 
   
'<br><br>The image was NOT created!';
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   
    $bool03 return: 
         1 (TRUE) if the image WAS created
     or  0 (FALSE) if the image WAS NOT created 
        
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

?> 

 RESULT   

GIF 003 03.gif

The image has been created!

GIF 003 03.gif apr

Note that no color was reported in this exercise, so a  black  background image was created.

This always happens when using imagecreate.


  4 EXERCISE   

<?php

$img04 
imagecreatetruecolor(150150);
// truecolor image
$blue imagecolorallocate($img0400255);
// it doesn't matter if the first color is provided
$red imagecolorallocate($img0425500);

$img_name "gif/GIF 004 04.gif";
// normal link

$bool04 imagegif($img04$img_name);
// black background

var_dump($img04);

if (
$bool04 == true)
{
echo 
'<br><br>$bool04 = ' $bool04 
 
'<br><br>The image has been created!<br><br>';

echo 
'<img src="' $img_name 
  
'" alt="' $img_name '" title="' $img_name '">';
}
else
{
echo 
'<br><br>$bool04 = ' $bool04 
     
'<br><br>The image was NOT created!';
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   
    $bool04 return: 
         1 (TRUE) if the image WAS created
     or  0 (FALSE) if the image WAS NOT created
        
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

?> 

 RESULT   

GIF 004 04.gif

The image has been created!

GIF 004 04.gif apr

Note that two colors was reported in this exercise, so a  black  background image was created.

This always happens when using imagecreatetruecolor.


  5 EXERCISE   

<?php

$img05 
imagecreate(150150);
// palette image
$blue imagecolorallocate($img050x000x000xFF);
// the first color to be used as background
$red imagecolorallocate($img050xff0x000x00);

$img_name "gif/GIF 005 05.gif";
// normal link

$bool05 imagegif($img05$img_name);

var_dump($img05);

if (
$bool05 == true)
{
echo 
'<br><br>$bool05 = ' $bool05 
      
'<br><br>The image has been created!<br><br>';

echo 
'<img src="' $img_name 
   
'" alt="' $img_name '" title="' $img_name '">';
}
else
{
echo 
'<br><br>$bool05 = ' $bool05 
    
'<br><br>The image was NOT created!';
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   
    $bool05 return: 
         1 (TRUE) if the image WAS created
     or  0 (FALSE) if the image WAS NOT created
        
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

?> 

 RESULT   

GIF 005 05.gif

The image has been created!

GIF 005 05.gif apr

Note that two colors were reported in this exercise, however, only the first was used to generate the background color of the image, in this case,  blue .

This always happens when using imagecreate.


NOTE

This exercise produces the same result as the first exercise on this page.

The difference is that the colors were expressed in hexadecimal values instead of decimal values.


  6 EXERCISE   

 <?php

header
('Content-type: image/gif');

$img06 imagecreate(150150);
$color06 imagecolorallocate($img06 ,128 ,1280);

imagegif($img06);

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   
       Image created on-the-fly 
       and not saved
       
       * SENDING TO BROWSER
           
       TO BE USED IF THERE ARE 
       NO PROBLEMS WITH headers
       
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

?> 

  7 EXERCISE   

<?php

// Try this code

$img07 imagecreate(100,100);
// 100px X 100px image

$img_name07 NULL;

imagegif($img07$img_name07);

?>