visualweber/gif-frame-extractor

PHP类,用于分离动画GIF中的所有帧(及其持续时间)

dev-master 2015-12-23 10:37 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:19:22 UTC


README

GifFrameExtractor

================================

GifFrameExtractor 是一个PHP类,用于分离动画GIF中的所有帧(及其持续时间)

用途是什么?

这个类可以帮助您分离动画GIF中的所有帧,例如添加水印后生成一个新的带水印的动画GIF。

使用方法

GifFrameExtractor 使用非常简单

1 - 提取

$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 ...
}

2 - 获取帧及其持续时间

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

选项

您可以选择是否获取原始帧(具有透明背景)或带有第二个参数的 extract() 方法的第一个帧上的帧

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

此选项默认为false。

关于

该类重新使用了 "PHP GIF Animation Resizer"(感谢Taha PAKSU)的一部分代码。