PHP code example of sybio / gif-frame-extractor

1. Go to this page and download the library: Download sybio/gif-frame-extractor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sybio / gif-frame-extractor example snippets


$gifFilePath = 'path/images/picture.gif';

if (GifFrameExtractor::isAnimatedGif($gifFilePath)) { // check this is an animated GIF
    
    $gfe = new GifFrameExtractor();
    $gfe->extract($gifFilePath);
    
    // Do something with extracted frames ...
}

foreach ($gfe->getFrames() as $frame) {
    
    // The frame resource image var
    $img = $frame['image'];
    
    // The frame duration
    $duration = $frame['duration'];
}

$frameImages = $gfe->getFrameImages();
$frameDurations = $gfe->getFrameDurations();

$totalDuration = $gfe->getTotalDuration(); // Total duration of the animated GIF
$frameNumber = $gfe->getFrameNumber(); // Number of extracted frames
var_dump($gfe->getFrameDimensions()); // An array containing the dimension of each extracted frame
var_dump($gfe->getFramePositions()); // An array containing the original positions of each extracted frame inside the GIF

$gfe->extract('path/images/picture.gif', true); // Can get transparency orignal frames