delfimov/gdimage

基于PHP-GD扩展的易于使用的图像处理工具

v1.5.0 2018-12-21 15:49 UTC

This package is auto-updated.

Last update: 2024-09-24 14:56:48 UTC


README

Latest Stable Version Build Status StyleCI SensioLabsInsight License

GDImage

基于PHP-GD扩展的易于使用的图像处理工具。

主要特点

  • 易于使用。
  • 支持JPEG、PNG、GIF、WEBP。
  • 方法链。
  • 基于EXIF头部的JPEG自动旋转(需要ext-exif扩展)
  • 易于调整大小、裁剪、旋转、添加文字、翻转、合并、设置不透明度

要求

如何安装

composer require delfimov/gdimage

或者将以下行添加到您的composer.json文件中

"delfimov/gdimage": "~1.0"

或者,将gdimage文件夹的内容复制到您的项目目录之一,并执行require 'src/GDImage.php';

简单示例

// initialize GDImage
$image = new GDImage('path/to/image.jpg');
 
// set fill color for empty image areas
$image->setFillColor([255, 0, 0]);

// Resize image. By default images are resized proportional and are not cropped,  
// with empty areas filled with color specified in setFillColor() method
$image->resize(1280, 720);

/* Add text to image 
The first parameter is text to add, 
the second parameter is optional, by default equals to: 
[
    'size' => 20,
    'angle' => 0,
    'x' => 0,
    'y' => 0,
    'color' => [0, 0, 0],
    'font' => '/../fonts/Roboto-Medium.ttf'
] 
*/
$image->addText(
    'Sample text to add',
    [
        'font' => __DIR__ . '/../fonts/Roboto-Medium.ttf',
        'size' => 18,
        'x' => 150,
        'y' => 100,
        'color' => [255, 0, 0]
    ]
);

// Save image
$image->save('path/to/newimage.jpg');

待办事项

  • 示例
  • README
  • 更多单元测试
  • 支持动画GIF