定制 mrfakename/php-gif-reborn 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

  1. Download the repo
  2. Open the src/Gif folder
  3. Copy GIFEncoder.php and GIFGenerator.php into your file
  4. 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.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固