Adding text | image | Spatie

 SPATIE

  Image
========

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Image](https://spatie.be/docs/image/v3)  Image-manipulations  Adding text

 Version   v3   v2   v1

 Other versions for crawler [v3](https://spatie.be/docs/image/v3) [v2](https://spatie.be/docs/image/v2) [v1](https://spatie.be/docs/image/v1)

- [ Introduction ](https://spatie.be/docs/image/v3/introduction)
- [ Postcardware ](https://spatie.be/docs/image/v3/postcardware)
- [ Installation and setup ](https://spatie.be/docs/image/v3/installation-and-setup)
- [ Supported formats ](https://spatie.be/docs/image/v3/formats)
- [ Questions &amp; issues ](https://spatie.be/docs/image/v3/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/image/v3/changelog)
- [ About us ](https://spatie.be/docs/image/v3/about-us)
- [ Upgrading ](https://spatie.be/docs/image/v3/upgrading)

Usage
-----

- [ Basic usage ](https://spatie.be/docs/image/v3/usage/basic-usage)
- [ Saving images ](https://spatie.be/docs/image/v3/usage/saving-images)
- [ Retrieving properties ](https://spatie.be/docs/image/v3/usage/retrieving-properties)
- [ Colors ](https://spatie.be/docs/image/v3/usage/colors)

Image manipulations
-------------------

- [ Overview ](https://spatie.be/docs/image/v3/image-manipulations/overview)
- [ Resizing images ](https://spatie.be/docs/image/v3/image-manipulations/resizing-images)
- [ Optimizing images ](https://spatie.be/docs/image/v3/image-manipulations/optimizing-images)
- [ Adjustments ](https://spatie.be/docs/image/v3/image-manipulations/adjustments)
- [ Image canvas ](https://spatie.be/docs/image/v3/image-manipulations/image-canvas)
- [ Effects ](https://spatie.be/docs/image/v3/image-manipulations/effects)
- [ Adding a watermark ](https://spatie.be/docs/image/v3/image-manipulations/adding-a-watermark)
- [ Adding text ](https://spatie.be/docs/image/v3/image-manipulations/text)

 Adding text
===========

###  On this page

1. [ Text position ](#content-text-position)
2. [ Font size ](#content-font-size)
3. [ Font color ](#content-font-color)
4. [ Font family ](#content-font-family)
5. [ Wrapping text ](#content-wrapping-text)

Using the `text` method you can easily position and add text. By default, it will be placed in the top left corner of the image.

```
$image->text('Hello there!');
```

Text position
-----------------------------------------------------------------------------------------------

Using the `x` and `y` parameters, you can set the location of the text.

### Example usage

```
$image->text('Hello there!', x: 10, y: 10);
```

Font size
-----------------------------------------------------------------------------------

Using the `fontSize` parameter, you can set the font size in pixels.

### Example usage

```
$image->text('Hello there!', fontSize: 100);
```

Font color
--------------------------------------------------------------------------------------

Using the `color` parameter, you can set the font color.

The color can be a color name (see [all available color names](https://developer.mozilla.org/en/docs/Web/CSS/color_value#Color_keywords)) or hexadecimal RGB(A).

### Example usage

```
$image->text('Hello there!', color: '');
```

Font family
-----------------------------------------------------------------------------------------

Using the `fontPath` parameter, which is required when using `GD` you can specify a path to a font to use

### Example usage

```
$image->text('Hello there!', fontPath: __DIR__ . '/arial.ttf');
```

Wrapping text
-----------------------------------------------------------------------------------------------

Using the `width` parameter, you can define a max width in pixels that the text should be and the package will wrap the text automatically.

### Example usage

```
$image->text('Hello there! This is a long piece of text that we should wrap.', width: 1000);
```
