aiger-team/image-tools 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

aiger-team/image-tools

Composer 安装命令:

composer require aiger-team/image-tools

包简介

Light image editing tool with immutable objects style

README 文档

README

A simple image editing tool for PHP. It uses the immutable object style. It means that an image object can't be changed after creation, the result of any modifying method of an image object is a new image object.

Installation

Composer

Add this to the composer.json file:

"require": {
  "aiger-team/image-tools": "~1.0.7"
}

and then call:

composer install

Or use the composer require command:

composer require aiger-team/image-tools

Manually

Download the files from GitHub, put them to your code directory and require them into your PHP code.

Examples

Resize an image:

use AigerTeam\ImageTools\ImageFactory;

(new ImageFactory())
	->openFile('image.jpg')
	->resize(600, 500)
	->toFile('image-resized.jpg');

Create a few thumbnails from an uploaded image and put a watermark on some of them:

use AigerTeam\ImageTools\ImageFactory;

// List of thumb to create. The values are width, height and "put watermark?".
$thumbsSizes = [
	[150, 80, false],
	[300, 200, true],
	[500, 400, true]
];

// Open uploaded image and watermark image
$factory   = new ImageFactory();
$image     = $factory->openFile($_FILES['image']['tmp_name']);
$watermark = $factory->openFile('watermark.png');

// Make thumbs
$thumbsFiles = array_map(function($size) use ($image, $watermark)
{
	$thumb = $image->resize($size[0], $size[1], false, $image::SIZING_COVER);	// Original $image is not modified so thumbs may be created in any order
	
	if ($size[2]) {
		$thumb = $thumb->stamp($watermark, 0.2);	// Watermark size is relative, not pixel
	}
		
	return $thumb->toUncertainFile('uploads/thumbs');	// File name and format is set automatically
}, $thumbSizes);

Reference

None of methods triggers errors or warnings. Instead of that methods throw exceptions. If some of them triggers an error please report us.

Creating Image object

An Image object can be created by various ways.

1. Using one of the ImageFactory object method

use AigerTeam\ImageTools\ImageFactory;

$factory = new ImageFactory();
$image = $factory->blank(100, 150);

See the PHPDoc in the ImageFactory class code for more details and the list of all image creating methods.

2. Passing a DG image resource to the Image constructor

use AigerTeam\ImageTools\Image;

$resource = imagecreatetruecolor(100, 150);
$image = new Image($resource);

The resource passed to the constructor becomes an Image object own. So the resource can be modified inside the constructor and the resource will be automatically destroyed on the Image object destruction.

Processing an image

Image object is immutable. The Image methods that modify image return a new object or the original object (if it's not modified). So this code is incorrect:

// WRONG! Don't do this or you will be fired.
$image->resize(200, 150);
$image->toFile('image.jpg');

This one is correct:

// Variant 1
$image = $image->resize(200, 150);
$image->toFile('image.jpg');

// Variant 2
$image
	->resize(200, 150)
	->toFile('image.jpg');

See the PHPDoc in the Image class code for more details and the list of all methods.

Version compatibility

Versions are backward compatible within minor versions. For example versions 1.1.3 and 1.1.5 are backward compatible, but versions 1.1.3 and 1.2.1 may be not compatible. So we advice you to set a specific minor version in the composer configuration, for example ~1.0.7.

License

ImageTools is licensed under the MIT License. See the LICENSE file for details.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固