yii\imagine\BaseImage::text PHP Method

text() public static method

Draws a text string on an existing image.
public static text ( string | resource | Imagine\Image\ImageInterface $image, string $text, string $fontFile, array $start = [0, 0], array $fontOptions = [] ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$text string the text to write to the image
$fontFile string the file path or path alias
$start array the starting position of the text. This must be an array with two elements representing `x` and `y` coordinates.
$fontOptions array the font options. The following options may be specified: - color: The font color. Defaults to "fff". - size: The font size. Defaults to 12. - angle: The angle to use to write the text. Defaults to 0.
return Imagine\Image\ImageInterface
    public static function text($image, $text, $fontFile, array $start = [0, 0], array $fontOptions = [])
    {
        if (!isset($start[0], $start[1])) {
            throw new InvalidParamException('$start must be an array of two elements.');
        }
        $fontSize = ArrayHelper::getValue($fontOptions, 'size', 12);
        $fontColor = ArrayHelper::getValue($fontOptions, 'color', 'fff');
        $fontAngle = ArrayHelper::getValue($fontOptions, 'angle', 0);
        $palette = new RGB();
        $color = $palette->color($fontColor);
        $img = self::ensureImageInterfaceInstance($image);
        $font = static::getImagine()->font(Yii::getAlias($fontFile), $fontSize, $color);
        $img->draw()->text($text, $font, new Point($start[0], $start[1]), $fontAngle);
        return $img;
    }