public text ( |
||
$image | ||
$text | string | The text to be written. |
$size | integer | The font size. Defaults to 12. |
$x | integer | The distance from the left edge of the image to the left of the text. Defaults to 0. |
$y | integer | The distance from the top edge of the image to the top of the text. Defaults to 12 (equal to font size) so that the text is placed within the image. |
$color | The Color object. Default text color is black. | |
$font | string | Full path to font file. If blank, will default to Liberation Sans font. |
$angle | integer | Angle of text from 0 - 359. Defaults to 0. |
return | Grafika\EditorInterface |
public function text(&$image, $text, $size = 12, $x = 0, $y = 0, $color = null, $font = '', $angle = 0)
{
if ($image->isAnimated()) {
// Ignore animated GIF for now
return $this;
}
$y += $size;
$color = $color !== null ? $color : new Color('#000000');
$font = $font !== '' ? $font : Grafika::fontsDir() . DIRECTORY_SEPARATOR . 'LiberationSans-Regular.ttf';
list($r, $g, $b, $alpha) = $color->getRgba();
$colorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, $this->gdAlpha($alpha));
imagettftext($image->getCore(), $size, $angle, $x, $y, $colorResource, $font, $text);
return $this;
}