sybio / gif-frame-extractor
PHP 类,用于分离动画 GIF 的所有帧(及其持续时间)
1.0.0
2012-10-13 09:06 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-12 01:16:27 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。
关于
该类重新使用了 Taha PAKSU 的 "PHP GIF Animation Resizer" 的一些代码部分(感谢他)。