imagecreatefromgif 


gd apg

CREATE a new image from file or URL from a GIF image.





This function returns an image identifier representing the image obtained from the given filename.

When reading GIF files into memory, only the first frame is returned in the image resource pointer.

The size of the image is not necessarily what is reported by getimagesize.





This function returns FALSE on errors.

The GdImage, resource or object returned by this function allows the creation of other image formats from GIF format.



<?php

GdImage
|false imagecreatefromgifstring $filename )


where,

$filename The path to an existing GIF image 

?>
 

  $filename   


The path or stream resource.

$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


  1 EXERCISE   

<?php

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

$img_file "gif/GIF 009 01.gif";

echo 
$img_file?><br><br>Existing Image
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="G I F" width="400">

<?php

$im01 
imagecreatefromgif($img_file);

echo 
'<br><br>resource or object for the 
            future image to be created by this function.<br><br>'
;
 
var_dump($im01);

imagedestroy($im01);

?> 

 RESULT   

GIF 009 01.gif

Existing image

GIF 009 01.gif apr

PHP 7

Resource for the created image:

resource(5) of type (gd)


PHP 8

Object for the created image:

object(GdImage)#1 (0) { }


  2 EXERCISE   

<?php

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

$img_file "gif/GIF 010 02.gif";

$img_name "png/PNG 019 02 (gif2png).png";

echo 
$img_file?><br><br>( Existing Image )
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="G I F">

<?php

$im02 
imagecreatefromgif($img_file);

echo 
'<br><br>$im02<br>The identifier to be used 
                       to create another image format:<br>'
;

var_dump($im02);

echo 
'<br><br>';

$bool02 imagepng($im02$img_name);  

if (
$bool02 == true)  
{  
echo 
'The new format of the image
           has been created!<br><br>' 
$img_name '<br><br>';  

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

?> 

 RESULT   

GIF 010 02.gif

Existing image

GIF 010 02.gif apr

The identifier to be used to create a:
.png image format:

resource(7) of type (gd)
or
object(GdImage)#1 (0) { }

The .png format of the image has been created!

PNG 019 02 (gif2png).png

PNG 019 02 (gif2png).png apr


  3 EXERCISE   

<?php

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

$img_file "gif/GIF 011 03.gif";

$img_name "gd2/GD2 004 03 (gif2gd2).gd2";

echo 
$img_file?><br><br>Existing Image
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="G I F">

<?php

$im03 
imagecreatefromgif($img_file);

echo 
'<br><br>$im03<br>The identifier to be used 
                       to create another image format:<br>'
;

var_dump($im03);

echo 
'<br><br>';

$bool03 imagegd2($im03$img_name);  

if (
$bool03 == true)  
{  
echo 
'The new format of the image
           has been created!<br><br>' 
$img_name '<br><br>';  

echo 
'Cannot be shown by this browser.<br><br>';   
}  
else  
{  
echo 
'$bool03 = ' $bool03 
   
'<br><br>The image was NOT created!';  
}  

?> 

 RESULT   

GIF 011 03.gif

Existing image

GIF 011 03.gif apr

The identifier to be used to create a:
.gd2 image format:

resource(14) of type (gd)
or
object(GdImage)#1 (0) { }

The .gd2 format of the image has been created!

GD2 004 03 (gif2gd2).gd2

Cannot be shown by this browser.


  4 EXERCISE   

<?php

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

$img_file "gif/GIF 011 03.gif";
// PALETTE IMAGE
// ( See the error )

$img_name "webp/WEBP 004 04 (gif2webp).webp";

echo 
$img_file?><br><br>Existing Image
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="G I F">

<?php

$im04 
imagecreatefromgif($img_file);

echo 
'<br><br>$im04<br>The identifier to be used 
                       to create another image format:<br>'
;

var_dump($im04);

echo 
'<br><br>';

$bool04 imagewebp($im04$img_name);  

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

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

?> 

 RESULT   

PHP VERSION: 8.2.18

GIF 011 03.gif

Existing Image


gif/GIF 011 03.gif apr

  5 EXERCISE   

<?php

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

$img_file "gif/GIF 011 03.gif";

$img_name "xbm/XBM 003 05 (gif2xbm).xbm";

echo 
$img_file?><br><br>Existing Image
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="G I F">

<?php

$im05 
imagecreatefromgif($img_file);

echo 
'<br><br>$im05<br>The identifier to be used 
                       to create another image format:<br>'
;

var_dump($im05);

echo 
'<br><br>';

$bool05 imagexbm($im05$img_name);  

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

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

?> 

 RESULT   

PHP VERSION: 8.2.18

GIF 011 03.gif

Existing Image


gif/GIF 011 03.gif apr