php imagttftext,Image With Text:一个在图像中嵌入文本的PHP库

这篇博客介绍了如何使用NMC/ImageWithText PHP库在图像上轻松添加多段独立样式的文本。你可以控制每段文本的对齐方式、颜色、字体、行高和大小,并通过指定坐标定位。示例代码展示了如何创建和渲染带有文本的图像。
摘要由CSDN通过智能技术生成

Image with Text

This class makes it super easy to render images with multiple, independently styled text blocks. You can control each text block's alignment, color, font, line height, and size. You may also position each text block with specific X and Y coordinates relative to the source image.

Installation

Install this library with Composer. Add this to your composer.json file:

{

"require": {

"nmcteam/image-with-text": "~2.0"

}

}

Then run composer install.

Usage

Here's a quick demonstration. You can find this full working demo in the example/ directory.

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');

How to Contribute

Fork the repo on GitHub and send a pull request

Find a list of TODOs on the GitHub issue tracker

We have not written any unit tests just yet, but we hope to do that soon.

Author

Copyright

(c) 2013 New Media Campaigns

License

MIT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值