Thursday, December 18, 2025
HomeLanguagesPHP | imagecreatefromgif() Function

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.




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


Output:

Example 2: Saving first frame as JPG in local folder




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


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

RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12036 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS