andrewgjohnson / linebreaks4imagettftext
linebreaks4imagettftext 是一个在用 PHP 的 imagettftext 函数时自动在文本中插入换行的函数
Requires
- php: >=5.0.0
- ext-gd: *
This package is auto-updated.
Last update: 2024-09-18 19:12:59 UTC
README
描述
linebreaks4imagettftext 是一个在用 PHP 的 imagettftext 函数时自动在文本中插入换行的函数。
linebreaks4imagettftext 是一个 agjgd 项目。
用法
使用 Composer
该项目支持 Composer 依赖管理器。您可以在 packagist.org 上找到 linebreaks4imagettftext 包。
使用 Composer 安装
运行以下命令
composer require andrewgjohnson/linebreaks4imagettftext
或将其添加到 composer.json 文件的 require
部分
"andrewgjohnson/linebreaks4imagettftext": "1.*"
不使用 Composer
要使用而不使用 Composer,请将 include 添加到 linebreaks4imagettftext.php
源文件。
include_once 'source/linebreaks4imagettftext.php';
示例
// You can use \andrewgjohnson\linebreaks4imagettftext() to add line breaks ("\n") to long strings to help format text when using imagettftext()
$string = 'It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way--in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.';
$stringWithLineBreaks = \andrewgjohnson\linebreaks4imagettftext(20, 0, $font, $string, 200);
echo $stringWithLineBreaks; //"It was the best of times, it was the\nworst of times, it was the age of\nwisdom, it was the age of\nfoolishness, it was the epoch of\nbelief, it was the epoch of\nincredulity, it was the season of\nLight, it was the season of\nDarkness, it was the spring of\nhope, it was the winter of despair,\nwe had everything before us, we\nhad nothing before us, we were all\ngoing direct to Heaven, we were all\ngoing direct the other way--in short,\nthe period was so far like the\npresent period, that some of its\nnoisiest authorities insisted on its\nbeing received, for good or for evil,\nin the superlative degree of\ncomparison only."
// This will work but there will be no line breaks so your text will likely overflow horizontally
imagettftext($im, 20, 0, 0, 0, $color, $font, $string);
// This will work and you will not have to worry about text overflowing
imagettftext($im, 20, 0, 0, 0, $color, $font, $stringWithLineBreaks);
GitHub 仓库和 linebreaks4imagettftext.agjgd.org 上包含了其他示例。
求助请求
如果您需要帮助,请将任何问题发布在 GitHub 的 讨论区域。
如果您发现一个错误,请在 GitHub 上 创建一个问题。在提交问题请使用我们的 问题模板。
贡献
如果您想贡献,请阅读我们的 贡献指南。
您可以通过在 patreon.com/agjopensource 成为 patron 来资助 linebreaks4imagettftext 和 其他 agjgd.org 项目。
致谢
此项目由 Andrew G. Johnson (@andrewgjohnson) 创建。
所有贡献者列表
我们的 安全策略和程序 来自 atomist/samples 项目。我们的 问题模板 来自 tensorflow/tensorflow 项目。我们的 拉取请求模板 来自 stevemao/github-issue-templates 项目。山峰照片来自 Gabriel Garcia Marengo。
变更日志
您可以在变更日志中找到所有显著的更改。