basekit/imanee

PHP 图像处理库

1 2015-10-15 16:10 UTC

README

Build Status Documentation Status Coverage Status License Join the chat at https://gitter.im/imanee/imanee

Imanee 是一个简单的 PHP 图像处理库。它提供了创建缩略图、水印、文本写入、动态 GIF 等的简便流程和方便的方法。

查看我们的实时演示以获取使用示例。查看我们的文档以获取详细说明。

需求

Imanee 需要 PHP >= 5.4,以及以下 PHP 图像扩展之一:ImagickGD。建议使用 Imagick,因为它具有更多功能,包括动态 GIF 支持(GD 中不可用)。

安装

首先请确保您的 PHP 服务器上已安装并启用了 Imagick 或 GD。如果系统中没有找到 Imagick,Imanee 将尝试使用 GD。

您可以通过 composer 容易地将 Imanee 添加到项目中

$ composer require imanee/imanee

入门指南

一些简单的示例以帮助您入门

### 缩略图输出

header("Content-type: image/jpg");

$imanee = new Imanee('path/to/my/image.jpg');
echo $imanee->thumbnail(200, 200)->output();

### 在图像顶部中央写入文本

header("Content-type: image/jpg");

$imanee = new Imanee('path/to/my/image.jpg');
echo $imanee->placeText('imanee test', 40, Imanee::IM_POS_MID_CENTER)
            ->output();

### 图像组合

header("Content-type: image/jpg");

$imanee = new Imanee('path/to/my/image.jpg');

/** places 4 different png images on the 4 corners of the original image */

echo $imanee->placeImage('img1.png', Imanee::IM_POS_TOP_LEFT)
    ->placeImage('img2.png', Imanee::IM_POS_TOP_RIGHT)
    ->placeImage('img3.png', Imanee::IM_POS_BOTTOM_LEFT)
    ->placeImage('img4.png', Imanee::IM_POS_BOTTOM_RIGHT)
    ->output()
;

### 从图像数组创建动态 GIF

$frames[] = 'img01.png';
$frames[] = 'img02.png';
$frames[] = 'img03.png';
$frames[] = 'img04.png';

header("Content-type: image/gif");

echo Imanee::arrayAnimate($frames, 30);

### 从目录中的文件创建动态 GIF

header("Content-type: image/gif");

echo Imanee::globAnimate('resources/*.jpg');

### 强制使用 GD

header("Content-type: image/jpg");

$imanee = new Imanee('path/to/my/image.jpg', new GDResource());
echo $imanee->thumbnail(200, 200)->output();

有关更多(和完整)示例,请查看演示仓库:https://github.com/imanee/demos