public function watermarkText($text, $pos = 0, $fontSize = 14, array $color = null, $font = null, $shadow = true)
    {
        if (!$color)
        {
            $color = [255, 255, 255, 0, 0, 0];
        }

        $font = (!$font) ? $this->fontFile : $font;

        if (!$this->newImage || !is_resource($this->newImage))
        {
            $this->newImage = $this->sourceImage;
            $sourceWidth    = $this->source['width'];
            $sourceHeight   = $this->source['height'];
        }
        else
        {
            $sourceWidth    = imagesx($this->newImage);
            $sourceHeight   = imagesy($this->newImage);
        }

        $textImage   = imagecreatetruecolor($sourceWidth, $sourceHeight);
        $textColor   = imagecolorallocate($textImage, $color[0], $color[1], $color[2]);
        $shadowColor = imagecolorallocate($textImage, $color[3], $color[4], $color[5]);

        // get 8 corners coordinates of the text watermark
        $size        = imagettfbbox($fontSize, 0, $font, $text);
        $textWidth   = $size[4];
        $textHeight  = abs($size[7]);

        $position    = $this->position($pos, $sourceWidth, $sourceHeight, $textWidth + 4, $textHeight, true, $fontSize);

        $posX = $position['x'];
        $posY = $position['y'];

        imagealphablending($textImage, true);
        imagesavealpha($textImage, true);

        imagecopymerge($textImage, $this->newImage, 0, 0, 0, 0, $sourceWidth, $sourceHeight, 100);

        if ($shadow)
        {
            imagettftext($textImage, $fontSize, 0, $posX + 1, $posY + 1, $shadowColor, $font, $text);
        }

        imagettftext($textImage, $fontSize, 0, $posX, $posY, $textColor, $font, $text);

        $this->newImage = $textImage;

        return $this;
    }
public function watermarkText($text, $pos = 0, $fontSize = 14, array $color = null, $font = null, $shadow = true)
    {
        if (!$color)
        {
            $color = [255, 255, 255, 0, 0, 0];
        }

        $font = (!$font) ? $this->fontFile : $font;

        if (!$this->newImage || !is_resource($this->newImage))
        {
            $this->newImage = $this->sourceImage;
            $sourceWidth    = $this->source['width'];
            $sourceHeight   = $this->source['height'];
        }
        else
        {
            $sourceWidth    = imagesx($this->newImage);
            $sourceHeight   = imagesy($this->newImage);
        }

        $textImage   = imagecreatetruecolor($sourceWidth, $sourceHeight);
        $textColor   = imagecolorallocate($textImage, $color[0], $color[1], $color[2]);
        $shadowColor = imagecolorallocate($textImage, $color[3], $color[4], $color[5]);

        // get 8 corners coordinates of the text watermark
        $size        = imagettfbbox($fontSize, 0, $font, $text);
        $textWidth   = $size[4];
        $textHeight  = abs($size[7]);

        $position    = $this->position($pos, $sourceWidth, $sourceHeight, $textWidth + 4, $textHeight, true, $fontSize);

        $posX = $position['x'];
        $posY = $position['y'];

        imagealphablending($textImage, true);
        imagesavealpha($textImage, true);

        imagecopymerge($textImage, $this->newImage, 0, 0, 0, 0, $sourceWidth, $sourceHeight, 100);

        if ($shadow)
        {
            imagettftext($textImage, $fontSize, 0, $posX + 1, $posY + 1, $shadowColor, $font, $text);
        }

        imagettftext($textImage, $fontSize, 0, $posX, $posY, $textColor, $font, $text);

        $this->newImage = $textImage;

        return $this;
    }
public function watermarkText ( $ text , $ pos = 0 , $ fontSize = 14 , array $ color = null , $ font = null , $ shadow = true ) { if ( ! $ color ) { $ color = [ 255 , 255 , 255 , 0 , 0 , 0 ] ; } $ font = ( ! $ font ) ? $ this -> fontFile : $ font ; if ( ! $ this -> newImage || ! is_resource ( $ this -> newImage ) ) { $ this -> newImage = $ this -> sourceImage ; $ sourceWidth = $ this -> source [ 'width' ] ; $ sourceHeight = $ this -> source [ 'height' ] ; } else { $ sourceWidth = imagesx ( $ this -> newImage ) ; $ sourceHeight = imagesy ( $ this -> newImage ) ; } $ textImage = imagecreatetruecolor ( $ sourceWidth , $ sourceHeight ) ; $ textColor = imagecolorallocate ( $ textImage , $ color [ 0 ] , $ color [ 1 ] , $ color [ 2 ] ) ; $ shadowColor = imagecolorallocate ( $ textImage , $ color [ 3 ] , $ color [ 4 ] , $ color [ 5 ] ) ; // get 8 corners coordinates of the text watermark
 $ size = imagettfbbox ( $ fontSize , 0 , $ font , $ text ) ; $ textWidth = $ size [ 4 ] ; $ textHeight = abs ( $ size [ 7 ] ) ; $ position = $ this -> position ( $ pos , $ sourceWidth , $ sourceHeight , $ textWidth + 4 , $ textHeight , true , $ fontSize ) ; $ posX = $ position [ 'x' ] ; $ posY = $ position [ 'y' ] ; imagealphablending ( $ textImage , true ) ; imagesavealpha ( $ textImage , true ) ; imagecopymerge ( $ textImage , $ this -> newImage , 0 , 0 , 0 , 0 , $ sourceWidth , $ sourceHeight , 100 ) ; if ( $ shadow ) { imagettftext ( $ textImage , $ fontSize , 0 , $ posX + 1 , $ posY + 1 , $ shadowColor , $ font , $ text ) ; } imagettftext ( $ textImage , $ fontSize , 0 , $ posX , $ posY , $ textColor , $ font , $ text ) ; $ this -> newImage = $ textImage ; return $ this ; }
Text watermark for image

@param string $text
@param int|array $pos 0
@param int $fontSize 14
@param array $color null
@param string $font null
@param bool $shadow true
@return $this
Text watermark for image