AgjGd
Description
AgjGd is a project that extends the functionality of PHP’s GD library started by Andrew G. Johnson. It is a single class, \AndrewGJohnson\AgjGd, with functionality exposed via public static methods.
Example
<?php
use AndrewGJohnson\AgjGd;
$image = imagecreatetruecolor(600, 300);
$font = 'NotoSans-Regular.ttf';
// Fill the image with a red-to-blue gradient
AgjGd::imagegradientrectangle(
$image,
0,
0,
imagesx($image) - 1,
imagesy($image) - 1,
AgjGd::imagecolorallocatefromstring($image, 'red'),
AgjGd::imagecolorallocatefromstring($image, 'blue')
);
// Wrap the text so that it does not overflow, then write it as blurred yellow text
$text = AgjGd::linebreaksfortext(30, 0, $font, 'Hello from AgjGd!', 500);
AgjGd::imagefttextfilter(
$image,
30,
0,
50,
150,
AgjGd::imagecolorallocatefromstring($image, 'yellow'),
$font,
$text,
[],
10
);
header('Content-Type: image/png');
imagepng($image);
You can find more examples and the full documentation for every method at AgjGd.org.
Methods
- AgjGd::imageblendedcolorallocate allocates a new blended color based on two existing allocated colors for your PHP GD images.
- AgjGd::imagecolorallocatefromstring allocates a color based on a string for your PHP GD images.
- AgjGd::imagefttextfilter is a drop-in replacement for
imagefttext/imagettftextwith added parameters to add filtered text enabling blur, glow and shadow effects on your PHP GD images. - AgjGd::imagefttextgradient is a drop-in replacement for
imagefttext/imagettftextwith added parameters to add gradient coloring effects to your PHP GD images. - AgjGd::imagegradientrectangle draws a gradient filled rectangle on your PHP GD images.
- AgjGd::linebreaksfortext automatically inserts line breaks into your text while using PHP’s
imagefttext/imagettftextfunctions.
Usage
With Composer
This project offers support for the Composer dependency manager. You can find the AgjGd package online on packagist.org.
Install using Composer
Either run this command:
composer require andrewgjohnson/agjgd
or add this to the require section of your composer.json file:
"andrewgjohnson/agjgd": "2.*"
Without Composer
To use without Composer add a require_once call for the AgjGd.php source file.
require_once 'source/AndrewGJohnson/AgjGd.php';
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 AgjGd.
Help Requests
Please post any questions in the discussions area of the GitHub repository.
If you discover a bug please enter an issue on the GitHub repository.
Acknowledgements
Full list of contributors:
- Andrew G. Johnson (@andrewgjohnson)
- Philip van Heemstra (@vHeemstra)
- Imgbot (@ImgBotApp)
- GitHub Actions (github-actions[bot])
Our security policies and procedures come via the atomist/samples project. Our pull request template comes via the stevemao/github-issue-templates project. The Jekyll theme was released by Andrew G. Johnson.
Changelog
You can find all notable changes in the changelog.







