text — Write text to an image

Description

public Intervention\Image\Image text(string $text, [integer $posx, [integer $posy, [Closure $callback]]])

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

Parameters

text

The text string that will be written to the image.

pos_x (optional)

X-Ordinate defining the basepoint of the first character. Default: 0

pos_y (optional)

Y-Ordinate defining the basepoint of the first character. Default: 0

callback (optional)

Closure callback on the font object to define more optional details. Use the following methods to pass details.

See examples of the callback usage below.

Font File

public Intervention\Image\Font file(string $filepath)

Set path to a True Type Font file or a integer value between 1 and 5 for one of the GD library internal fonts. Default: 1

Font Size

public Intervention\Image\Font size(integer $size)

Set font size in pixels. Font sizing is only available if a font file is set and will be ignored otherwise. Default: 12

Font Color

public Intervention\Image\Font color(mixed $color)

Set color of the text in one of the available color formats. Default: #000000

Horizontal Alignment

public Intervention\Image\Font align(string $align)

Set horizontal text alignment. Possible values are left, right and center. Default: left

Vertical Alignment

public Intervention\Image\Font valign(string $valign)

Set vertical text alignment. Possible values are top, bottom and middle. Default: bottom

Rotation Angle

public Intervention\Image\Font angle(integer $angle)

Set rotation angle of text in degrees. Text will be rotated counter-clockwise around the vertical and horizontal aligned point. Rotation is only available if a font file is set and will be ignored otherwise. Default: no rotation

Return Values

Instance of Intervention\Image\Image

Examples

  1. // create Image from file
  2. $img = Image::make('public/foo.jpg');
  3. // write text
  4. $img->text('The quick brown fox jumps over the lazy dog.');
  5. // write text at position
  6. $img->text('The quick brown fox jumps over the lazy dog.', 120, 100);
  7. // use callback to define details
  8. $img->text('foo', 0, 0, function($font) {
  9. $font->file('foo/bar.ttf');
  10. $font->size(24);
  11. $font->color('#fdf6e3');
  12. $font->align('center');
  13. $font->valign('top');
  14. $font->angle(45);
  15. });
  16. // draw transparent text
  17. $img->text('foo', 0, 0, function($font) {
  18. $font->color(array(255, 255, 255, 0.5))
  19. });