redbutton / gif-creator
此包已被废弃,不再维护。未建议替代包。
PHP类,可从多张图片中创建动态GIF
1.0.1
2020-06-17 08:31 UTC
Requires
- php: >=7.4.0
This package is auto-updated.
Last update: 2024-02-07 13:16:43 UTC
README
GifCreator
================================
GifCreator是一个PHP类,用于从多张图片中创建动态GIF
用途?
此类帮助您创建动态GIF图像:提供多张图片及其持续时间即可!
使用方法
1 - 创建
// Create an array containing file paths, resource var (initialized with imagecreatefromXXX),
// image URLs or even binary code from image files.
// All sorted in order to appear.
$frames = array(
imagecreatefrompng("/../images/pic1.png"), // Resource var
"/../images/pic2.png", // Image file path
file_get_contents("/../images/pic3.jpg"), // Binary source code
'http://thisisafakedomain.com/images/pic4.jpg', // URL
);
// Create an array containing the duration (in millisecond) of each frames (in order too)
$durations = array(40, 80, 40, 20);
// Initialize and create the GIF !
$gc = new GifCreator();
$gc->create($frames, $durations, 5);
create()方法的第三个参数允许您选择动画GIF在停止前的循环次数。在之前的示例中,我选择了5次循环。设置为0(零)以获得无限循环。
2 - 获取结果
现在您可以得到动画GIF的二进制文件
$gifBinary = $gc->getGif();
然后您可以在浏览器中显示它
header('Content-type: image/gif');
header('Content-Disposition: filename="butterfly.gif"');
echo $gifBinary;
exit;
或者将其保存为GIF文件到文件夹中
file_put_contents('/myfolder/animated_picture.gif', $gifBinary);
行为
- 透明度基于第一个提供的帧。只有当您提供具有相同透明背景的多个帧时,才会保存。
- 生成的GIF的尺寸基于第一个帧。如果您需要调整帧的大小以获得相同的尺寸,可以使用此类:https://github.com/Sybio/ImageWorkshop
关于
该类重用了由László Zsidi编写的"GIFEncoder.class.php"代码的一部分(感谢他)。