andrewgjohnson / linebreaks4imagettftext
linebreaks4imagettftext is a function to automatically insert line breaks into your text while using PHP’s imagettftext() function
Package info
github.com/andrewgjohnson/linebreaks4imagettftext
pkg:composer/andrewgjohnson/linebreaks4imagettftext
Requires
- php: >=5.3.0
- ext-gd: *
Requires (Dev)
This package is auto-updated.
Last update: 2026-05-15 03:19:12 UTC
README
Description
linebreaks4imagettftext is a function to automatically insert line breaks into your text while using PHP’s imagettftext() function.
linebreaks4imagettftext is an agjgd project.
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 be 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 included in the GitHub repository and on linebreaks4imagettftext.agjgd.org.
Usage
With Composer
This project offers support for the Composer dependency manager. You can find the linebreaks4imagettftext package online on packagist.org.
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 to the linebreaks4imagettftext.php source file.
include_once 'source/AndrewGJohnson/AgjGd/linebreaks4imagettftext.php';
Help Requests
Please post any questions in the discussions area on GitHub if you need help.
If you discover a bug please enter an issue on GitHub. When submitting an issue please use our issue template.
Contributing
Please read our contributing guidelines if you want to contribute.
You can contribute financially by becoming a patron at patreon.com/agjopensource to support linebreaks4imagettftext and other agjgd.org projects.
Acknowledgements
This project was started by Andrew G. Johnson (@andrewgjohnson).
Full list of contributors:
Our security policies and procedures comes via the atomist/samples project. Our issue templates comes via the tensorflow/tensorflow project. Our pull request template comes via the stevemao/github-issue-templates project. The mountains photo comes via Gabriel Garcia Marengo.
Changelog
You can find all notable changes in the changelog.