PHP | imagecreatefromgif() Function

The imagecreatefromgif() function is an inbuilt function in PHP which is used to create a new image from a given part of GIF file or URL. Further, this image can be worked upon in the program. This function only loads the first frame of the animation.

Syntax:

resource imagecreatefromgif( string $filename )

Parameters: This function accepts a single parameter $filename which holds the image.



Return Value: This function returns an image resource identifier on success, FALSE on errors.

Below examples illustrate the imagecreatefromgif() function in PHP:

Example 1: Loading first frame in browser.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an image from gif
$im = imagecreatefromgif(
  
// View the image
header("Content-Type: image/gif");
imagegif($im);
imagedestroy($im);
?>

chevron_right


Output:

Example 2: Saving first frame as JPG in local folder

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an image from gif
$im = imagecreatefromgif(
  
// Save the image as jpeg
imagejpeg($im, 'firstframe.jpg');
imagedestroy($im);
?>

chevron_right


Output:

This will save the first frame as firstframe.jpg in the same folder.

Note: Only the first frame is returned in the image resource pointer.

Reference: https://www.php.net/manual/en/function.imagecreatefromgif.php

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.