thapp/image

图像处理程序

v1.0.0beta1 2015-01-29 16:39 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:08:24 UTC


README

Build Status Code Climate Coverage Status HHVM Status Latest Stable Version Latest Unstable Version License

此模块是为在 Thapp\JitImage 中使用而创建的,但也可以作为一个独立的库来处理图像。它高度受 Imagine 库的启发,但解决了视图的缺陷,但也更加有限。

安装

在项目目录中要求 thapp/image

$ composer require thapp/image

或者将其添加到你的 composer.json

{
	"require": {
		"thapp/image": "dev-master"
	}
}

使用方法

快速示例

<?php

use Thapp\Image\Geometry\Size;
use Thapp\Image\Driver\Imagick\Source;

$source = new Source;
$image = $source->load('image.jpg');

$image->edit()->crop(new Size(100, 100));

$image->save('newimage.jpg');

加载源文件

Source 对象能够从文件路径、文件句柄或二进制字符串创建 Image 实例

<?php

use Thapp\Image\Driver\Imagick\Source;

$source = new Source;
$image = $source->load('image.jpg');
// or read the file from a file handle:
$handle = fopen('image.jpg', 'r+');
$image = $source->read($handle);
// or read the file from a binary string:
$content = file_get_contents('image.jpg');
$image = $source->create($content);

Source 类将其第一个参数设置为 Thapp\Image\Info\MetaDataReaderInterface 实例。该 $reader 用于读取图像的元信息。这在例如你想根据图像的方向自动旋转图像时非常有用。

默认情况下,为你创建了一个新的 Thapp\Image\Info\ImageReader 实例。 ImageReader 能够读取从 php 的 getimagesize() 函数派生出的基本图像信息。

你可以使用 Thapp\Image\Info\ImageReader 类,它提供了更广泛的信息(例如,对于 GDGmagick 驱动程序,用于确定正确的图像方向)。

<?php

use Thapp\Image\Info\ExifReader;
use Thapp\Image\Driver\Imagick\Source;

$source = new Source(new ExifReader);

// ...

$image = $source->load('image.jpg');