GD Text

Making it easy to type text on pictures.


Native PHP library, needed only the GD Extension, supporting multi-lined text, horizontal and vertical alignment, automatic text wrapping, text rotation and color

The library is compatible with any PHP app with the GD Extension.

The library accepts any GD resource and can be used with any library able to return a GD resource.

...

Features


Framework Free

Need only the GD Extension

Use your font

Support any TrueType Font

Friendly

Manage your text as box to customize

GitHub


Fork the project on GitHub

It is open source! Hosted, developed, and maintained on GitHub.


View GitHub Project

Patreon


Support this project on Patreon

This project is free and will remain free, but its development is not. If you like it and help us maintain it and evolve it, don't hesitate to support us on Patreon.


Support it

Example



<?php

declare(strict_types=1);

namespace
Acme;

use
GDText\Box;
use
GDText\Color;
use
GDText\Enum\HorizontalAlignment;
use
GDText\Enum\TextWrapping;
use
GDText\Enum\VerticalAlignment;

use function
file_get_contents;
use function
imagealphablending;
use function
imagecreatefromstring;
use function
imagepng;
use function
imagesavealpha;

require_once
'vendor/autoload.php';

$im = imagecreatefromstring(file_get_contents('images/foo.png'));

imagealphablending($im, true);
imagesavealpha($im, true);

$box = new Box($im);
$box->setFontFace(__DIR__ . '/LinLibertine_R.ttf'); // http://www.dafont.com/franchise.font
$box->setFontColor(new Color(255, 75, 140));
$box->setFontSize(16);
$box->setBox(0, 135, imagesx($im), 70);
$box->setTextAlign(HorizontalAlignment::Left, VerticalAlignment::Top);

$box->setTextWrapping(TextWrapping::WrapWithOverflow);
$box->draw('Owls are birds');

imagepng($im, 'foo2.png');