nmcteam/image-with-text

创建嵌入文本和高级排版的图像

2.2.0 2017-10-26 16:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:06:06 UTC


README

此类使渲染包含多个独立样式文本块的图像变得非常简单。您可以控制每个文本块的排列、颜色、字体、行高和大小。您还可以使用相对于源图像的X和Y坐标定位每个文本块。

安装

使用 Composer 安装此库。将其添加到您的 composer.json 文件中

{
    "require": {
        "nmcteam/image-with-text": "~2.0"
    }
}

然后运行 composer install

使用方法

这是一个快速演示。您可以在 example/ 目录中找到这个完整的演示。

<?php
require '../vendor/autoload.php';

// Create image
$image = new \NMC\ImageWithText\Image(dirname(__FILE__) . '/source.jpg');

// Add styled text to image
$text1 = new \NMC\ImageWithText\Text('Thanks for using our image text PHP library!', 3, 25);
$text1->align = 'left';
$text1->color = 'FFFFFF';
$text1->font = dirname(__FILE__) . '/Ubuntu-Medium.ttf';
$text1->lineHeight = 36;
$text1->size = 24;
$text1->startX = 40;
$text1->startY = 40;
$image->addText($text1);

// Add another styled text to image
$text2 = new \NMC\ImageWithText\Text('No, really, thanks!', 1, 30);
$text2->align = 'left';
$text2->color = '000000';
$text2->font = dirname(__FILE__) . '/Ubuntu-Medium.ttf';
$text2->lineHeight = 20;
$text2->size = 14;
$text2->startX = 40;
$text2->startY = 140;
$image->addText($text2);

// Render image
$image->render(dirname(__FILE__) . '/destination.jpg');

如何贡献

  • 在GitHub上Fork此仓库并提交pull request
  • 在GitHub问题跟踪器中查找待办事项列表

我们还没有编写任何单元测试,但我们希望很快就能做到。

作者

Josh Lockhart

版权

© 2013 New Media Campaigns

许可证

MIT