mrfakename/php-gif-reborn
最新稳定版本:v3.0.4
Composer 安装命令:
composer require mrfakename/php-gif-reborn
包简介
README 文档
README
What is phpgif?
phpgif is a PHP library to generate GIFs - easily!
Installing phpgif
Using Composer
Run the following command in Terminal or Command Prompt:
composer require phpgif/phpgif
use phpgif\GIF\GifGenerator
Without Composer
When using shared hosting, many hosting providers don't allow Composer. Use the following system to install PHP-GIF-Reborn.
- Download the repo
- Open the src/Gif folder
- Copy GIFEncoder.php and GIFGenerator.php into your file
- Paste the following code at the top of your file:
include 'GIFEncoder.php'; include 'GIFGenerator.php';
Getting Started
Create a PHP file and add these headers at the beginning of the file:
// Caching disable headers header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // Output as a GIF image header ('Content-type:image/gif'); // Import the GIFEncoder and GIFGenerator PHP files include 'GIFEncoder.php'; include 'GIFGenerator.php';
On the next lines you can create a GIF image by first initializing the GIFGenerator object and creating an array with all the image frames:
// Initialize a new GIFGenerator object $gif = new GIFGenerator(); // Create a multidimensional array with all the image frames $imageFrames = array( 'repeat' => false, 'transparent' => false, 'frames' => array( array( 'image' => './images/newyear.jpg', 'text' => array( array( 'text' => 'Hello GIF frame 1', 'fonts-color' => '#000', 'x-position' => 140, 'y-position' => 138 ) ), 'delay' => 100 ), ) );
Finally you generate the image and echo the results on the screen:
echo $gif->generate($imageFrames);
Example
A more complete example. You could copy/paste below code to a file and execute it in the browser to view a more complete result. As you can see it's not required to use text in your GIF image and you can add as much text per frame, and as much frames per GIF image as you like.
<?php // Caching disable headers header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // Output as a GIF image header ('Content-type: image/gif'); // Include the GIFEncoder and GIFGenerator PHP files include 'GIFEncoder.php'; include 'GIFGenerator.php'; // Initialize a new GIFGenerator object $gif = new GIFGenerator(); // Create a multidimensional array with all the image frames $imageFrames = array( 'repeat' => 5, 'transparent' => true, 'frames' => array( array( 'image' => './images/newyear.jpg', 'text' => array( array( 'text' => 'Hello GIF frame 1', 'fonts' => './fonts/Lato-Light.ttf', 'fonts-size' => 30, 'angle' => 0, 'fonts-color' => '#000', 'x-position' => 140, 'y-position' => 138 ) ), 'delay' => 100 ), array( 'image' => './images/newyear.jpg', 'text' => array( array( 'text' => 'Hello GIF frame 2', 'fonts' => './fonts/Lato-Light.ttf', 'fonts-size' => 15, 'angle' => 0, 'fonts-color' => '#000', 'x-position' => 140, 'y-position' => 138 ), array( 'text' => 'Hello GIF frame 2', 'fonts' => './fonts/Lato-Light.ttf', 'fonts-size' => 15, 'angle' => 0, 'fonts-color' => '#000', 'x-position' => 140, 'y-position' => 108 ) ), 'delay' => 100 ), array( 'image' => './images/newyear.jpg', 'delay' => 50 ) ) ); echo $gif->generate($imageFrames);
License & Credits
This software is published under the MIT License.
Original Code
phpgif is based off of PHP-GIF
GIFEncoder
GIFEncoder.class.php is adapted from the GIFEncoder PHP class by László Zsidi.
mrfakename/php-gif-reborn 适用场景与选型建议
mrfakename/php-gif-reborn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mrfakename/php-gif-reborn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrfakename/php-gif-reborn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-06