PHPackages                             ghostff/php-text-to-image - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. ghostff/php-text-to-image

ActiveLibrary[Image &amp; Media](/categories/media)

ghostff/php-text-to-image
=========================

Add text to an existing or new image

v1.0.0(4y ago)2315.7k↓32.7%8[2 PRs](https://github.com/Ghostff/PHP-Add-text-to-image/pulls)MITPHPPHP &gt;=7.0.0

Since Dec 4Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Ghostff/PHP-Add-text-to-image)[ Packagist](https://packagist.org/packages/ghostff/php-text-to-image)[ RSS](/packages/ghostff-php-text-to-image/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP-add-text-to-image
=====================

[](#php-add-text-to-image)

Add text to an existing or new image. PHP &gt;= 7.0

```
composer require ghostff/php-text-to-image
```

### Usage

[](#usage)

```
$text1 = Text::from('Text One')->color(231, 81, 0);

$text2 = Text::from('Text Two')->color(130, 146, 145)->position(260, 35);

$text3 = (new Text('Text Three'))->set(150, 0, [0, 0, 252], '', 10, 1, 1, [50, 205, 50]);

$text  = Text::from('Text!')
            ->position(170, 150)
            ->font(20, __DIR__ . '/sweet purple.otf')
            ->shadow(2, 2, [255])
            ->color(255,255, 0)
            ->rotate(20);
```

Writing to existing image

```
{
    header("Content-Type: image/png");
    echo (new TextToImage(__DIR__ . '/default.png'))->addTexts($text1, $text2, $text3, $text)->render();
}

// Or save to a file
(new TextToImage(__DIR__ . '/default.png'))->addTexts($text1, $text2, $text3, $text)->render(__DIR__ . '/tmp.png')
```

Writing to a new image:

```
{
    header("Content-Type: image/png");
    echo (new TextToImage())->setDimension(350, 350)->setBackgroundColor(0, 0, 0)->addTexts($text1, $text2, $text3, $text)->render();
}

// Or save to a file
(new TextToImage())->setDimension(350, 350)->setBackgroundColor(0, 0, 0)->addTexts($text1, $text2, $text3, $text)->render(__DIR__ . '/tmp.png');
```

---

### `TextToImage` Documentations

[](#texttoimage-documentations)

`TextToImage::__construct(string $from = '')`
**Description:** Creates TextToImage instance.

ParamsDescriptionfromThe image text will be added to. If not specified a blank image 200x200 will be created---

`TextToImage::setDimension(int $width, int $height): TextToImage`
**Description:** Set background image dimension. **Note: This is not evaluated if `$from` argument is passed to the constructor**

ParamsDescriptionwidthThe width of the background image.heightThe height of the background image.---

`TextToImage::setBackgroundColor(int $r = 255, int $g = 255, int $b = 255, int $a = 255): TextToImage`
**Description:** Set the background color of created background image. **Note: This is not evaluated if `$from` argument is passed to the constructor.**

ParamsDescriptionrValue of red component.gValue of green component.bValue of blue component.aA value between 0 and 255. 255 indicates completely opaque while 0 indicates completely transparent.---

`TextToImage::addTexts(Text $text, Text ...$texts): TextToImage`
**Description:** Adds text to specified or generated background image.

ParamsDescriptiontext`Text` to add to imagetextsFurther `Text` to add to imageMultiple text can all be added at once or over steps.

```
$hello  = Text::from('Hello');
$world  = Text::from('World')->position(0, 15);
$foo    = Text::from('Foo')->position(0, 30);
$bar    = Text::from('Bar')->position(0, 45);
$foobar = Text::from('Foobar')->position(0, 60)->color(255, 0, 0);

$text_image = new TextToImage();
$text_image->addTexts($hello, $world, $foo);
$text_image->addTexts($bar);
echo $text_image->setBackgroundColor(0, 0, 0)->addTexts($foobar)->render();
```

---

`TextToImage::render(string $save_as = null, string $ext = null): string`
**Description:** Renders modified image to a file or return contents.

ParamsDescriptionsave\_asIf specified, image content will be saved at the provided path..extImage processor. possible values: `jpg`, `jpeg`, `png` or `gif`.---

### `Text` Documentations

[](#text-documentations)

`Text::__construct(string $from = '')` or `Text::__from(string $text): Text`
**Description:** Creates Text instance.

ParamsDescriptiontextThe text that will be written on image.`Text::position(int $x, int $y = 0): Text`
**Description:** Sets the position of specified text on image.

ParamsDescriptionxThe X position.yThe Y position.---

`Text::font(int $size, string $path = null): Text`
**Description:** Sets the font/size of specified text.

ParamsDescriptionsizeThe font size of text.pathThe path to font file.---

`Text::color(int $r = 255, int $g = 255, int $b = 255, int $a = 255): Text`
**Description:** Sets the color of specified text.

ParamsDescriptionrValue of red component.gValue of green component.bValue of blue component.aA value between 0 and 255. 255 indicates completely opaque while 0 indicates completely transparent.---

`Text::shadow(int $position_x = null, int $position_y = null, array $color = []): Text`
**Description:** Adds shadow to specified text.

ParamsDescriptionposition\_xThe shadow's X position.position\_yThe shadow's Y position.colorArray \[r(red), g(green), b(blue), a(alpha)\] See color method.```
Text::from('FooBar')->shadow(1, 1, [0, 0, 255]);
// Create Text with half the max opacity
Text::from('FooBar')->shadow(1, 1, [0, 0, 255, 255 / 2]);
```

---

`Text::rotate(float $degrees): Text`
**Description:** Rotates specified text to a specific angle.

ParamsDescriptiondegreesThe angle in degrees.---

`Text::update(Closure $closure): Text`
**Description:** Runtime text update.

ParamsDescriptiondegreesThe function to call before render. If specified, this closure will be called with three arguments `TextToImage`, `Text` and `GdFont````
$text = Text::from('FooBar')->shadow(1, 1, [0, 0, 255]);
$text->update(function (TextToImage $text_to_image, Text $text, $image) {
    // Basic centering of text.
    $text->position(intval($text_to_image->getHeight() / 2), intval($text_to_image->getWidth() / 2));
});
```

---

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1627d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15882122?v=4)[ghostff](/maintainers/Ghostff)[@Ghostff](https://github.com/Ghostff)

---

Top Contributors

[![Ghostff](https://avatars.githubusercontent.com/u/15882122?v=4)](https://github.com/Ghostff "Ghostff (20 commits)")

---

Tags

imageimage-processingphpphp7text

### Embed Badge

![Health badge](/badges/ghostff-php-text-to-image/health.svg)

```
[![Health](https://phpackages.com/badges/ghostff-php-text-to-image/health.svg)](https://phpackages.com/packages/ghostff-php-text-to-image)
```

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)[humanmade/tachyon-plugin

Rewrites WordPress image URLs to use Tachyon

87338.5k2](/packages/humanmade-tachyon-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
