https://github.com/andrewgjohnson/linebreaks4imagettftext
linebreaks4imagettftext is a function to automatically insert line breaks into your text while using PHP's imagettftext function.
https://github.com/andrewgjohnson/linebreaks4imagettftext
composer gd graphics image images php
Last synced: about 1 month ago
JSON representation
linebreaks4imagettftext is a function to automatically insert line breaks into your text while using PHP's imagettftext function.
- Host: GitHub
- URL: https://github.com/andrewgjohnson/linebreaks4imagettftext
- Owner: andrewgjohnson
- License: mit
- Created: 2018-06-02T23:46:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-18T19:02:25.000Z (almost 2 years ago)
- Last Synced: 2025-02-27T10:39:13.349Z (over 1 year ago)
- Topics: composer, gd, graphics, image, images, php
- Language: PHP
- Homepage: https://linebreaks4imagettftext.agjgd.org
- Size: 2.43 MB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
- Support: .github/SUPPORT.md
Awesome Lists containing this project
README
# linebreaks4imagettftext
[](https://github.com/andrewgjohnson/linebreaks4imagettftext/blob/master/LICENSE)
[](https://github.com/andrewgjohnson/linebreaks4imagettftext/releases)
[](https://github.com/andrewgjohnson/linebreaks4imagettftext/graphs/contributors)
[](https://packagist.org/packages/andrewgjohnson/linebreaks4imagettftext/stats)
[](https://github.com/andrewgjohnson/linebreaks4imagettftext/issues)
[](https://patreon.com/agjopensource)
## Description
**linebreaks4imagettftext** is a function to automatically insert line breaks into your text while using PHP’s imagettftext() function.
[](https://patreon.com/agjopensource)
**linebreaks4imagettftext** is an [agjgd](https://agjgd.org) project.
## Usage
### With Composer
This project offers support for the [Composer](https://getcomposer.org/) dependency manager. You can find the linebreaks4imagettftext package online on [packagist.org](https://packagist.org/packages/andrewgjohnson/linebreaks4imagettftext).
#### Install using Composer
Either run this command:
composer require andrewgjohnson/linebreaks4imagettftext
or add this to the `require` section of your composer.json file:
"andrewgjohnson/linebreaks4imagettftext": "1.*"
### Without Composer
To use without Composer add an [include](http://php.net/manual/function.include.php) to the [`linebreaks4imagettftext.php` source file](https://raw.githubusercontent.com/andrewgjohnson/linebreaks4imagettftext/master/source/linebreaks4imagettftext.php).
include_once 'source/linebreaks4imagettftext.php';
## Example
// You can use linebreaks4imagettftext() to add line breaks ("\n") to long strings to help format text when using imagettftext()
$string = 'This is a long sentence that could not fit on a single line.';
$stringWithLineBreaks = \AndrewGJohnson\AgjGd\linebreaks4imagettftext(20, 0, $font, $string, imagesx($im) * 0.8);
// This will work but there will are no line breaks so your text will likely overflow horizontally
imagettftext($im, 20, 0, imagesx($im) * 0.1, 0, $color, $font, $string);
// This will work and you will not have to worry about text overflowing regardless of string length
imagettftext($im, 20, 0, imagesx($im) * 0.1, 0, $color, $font, $stringWithLineBreaks);
There are [other examples](https://github.com/andrewgjohnson/linebreaks4imagettftext/tree/master/examples) included in the GitHub repository and on [linebreaks4imagettftext.agjgd.org](https://linebreaks4imagettftext.agjgd.org/examples/).
## Help Requests
Please post any questions in the [discussions area](https://github.com/andrewgjohnson/linebreaks4imagettftext/discussions) on GitHub if you need help.
If you discover a bug please [enter an issue](https://github.com/andrewgjohnson/linebreaks4imagettftext/issues/new) on GitHub. When submitting an issue please use our [issue template](https://github.com/andrewgjohnson/linebreaks4imagettftext/tree/master/.github/ISSUE_TEMPLATE).
## Contributing
Please read our [contributing guidelines](https://github.com/andrewgjohnson/linebreaks4imagettftext/blob/master/.github/CONTRIBUTING.md) if you want to contribute.
You can contribute financially by becoming a [patron](https://patreon.com/agjopensource) at [patreon.com/agjopensource](https://patreon.com/agjopensource) to support linebreaks4imagettftext and [other agjgd.org projects](https://agjgd.org/projects/).
[](https://patreon.com/agjopensource)
## Acknowledgements
This project was started by [Andrew G. Johnson (@andrewgjohnson)](https://github.com/andrewgjohnson).
Full list of contributors:
* [Andrew G. Johnson (@andrewgjohnson)](https://github.com/andrewgjohnson)
Our [security policies and procedures](https://github.com/andrewgjohnson/linebreaks4imagettftext/blob/master/.github/SECURITY.md) comes via the [atomist/samples](https://github.com/atomist/samples/blob/master/.github/SECURITY.md) project. Our [issue templates](https://github.com/andrewgjohnson/linebreaks4imagettftext/tree/master/.github/ISSUE_TEMPLATE) comes via the [tensorflow/tensorflow](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) project. Our [pull request template](https://github.com/andrewgjohnson/linebreaks4imagettftext/blob/master/.github/PULL_REQUEST_TEMPLATE.md) comes via the [stevemao/github-issue-templates](https://github.com/stevemao/github-issue-templates) project. The [mountains photo](https://unsplash.com/photos/qJvpykJ5SKs) comes via [Gabriel Garcia Marengo](https://unsplash.com/@gabrielgm).
## Changelog
You can find all notable changes in the [changelog](https://github.com/andrewgjohnson/linebreaks4imagettftext/blob/master/CHANGELOG.md).