Writing text

public Image::text(string $text, int $x, int $y, callable $settings): ImageInterface

Write a text string at the basepoint position of x, y to the current image. You can define more details like font-size, font-file and alignment via a callback as the fourth parameter.


Name Type Description
text string The text that will be written to the image.
x integer Coordinate on x-axis defining the base point of the first character.
y integer Coordinate on y-axis defining the base point of the first character.
settings callable Callback function to configure the font appearance.


use Intervention\Image\ImageManager;

// create new image instance
$image = ImageManager::gd()->read('images/example.jpg');

// write text at a certain position
$image->text('The quick brown fox', 120, 100);

Text & font settings

To define the overall appearance of the text and set more details you can pass a callback as an optional parameter. The callback places the calls on the FontInterface and listens to the following methods.


use Intervention\Image\ImageManager;

// create test image
$image = ImageManager::imagick()->read('images/example.jpg');

// write text to image
$image->text('The quick brown fox', 120, 100, function ($font) {

Font size

public FontInterface::size(float $size): FontInterface

Define a font size. By default a value of 12 will be applied.


Name Type Description
size float Font size to be applied

Font file

public FontInterface::filename(string $filename): FontInterface

Set a path to a font file in file system in which the text should be written.


Name Type Description
filename string Path to a valid font file


public FontInterface::color(mixed $color): FontInterface

Define the text color in one of the valid color formats.


Name Type Description
color mixed Desired color of text

Horizontal alignment

public FontInterface::align(string $align): FontInterface

Define the horizontal alignment of the text to be written starting from the base point. Possible values are left, right and center. Default: left


Name Type Description
align string Horizontal text alignment

Vertical alignment

public FontInterface::valign(string $valign): FontInterface

Define the vertical alignment of the text to be written starting from the base point. Possible values are top, bottom and middle. Default: bottom


Name Type Description
valign string Vertical text alignment


public FontInterface::angle(float $angle): FontInterface

Rotate the text block clockwise with a desired angle.


Name Type Description
angle float Rotation angle

Line height

public FontInterface::lineHeight(float $height): FontInterface

Define the line height of the text block. Applies only for multi line text. Default value is 1.25.


Name Type Description
height float Line height for multi line text block