public function writeText($text, $point, $size, $angle, $font, $maxwidth = 0, $rgbAr = null, $textAlignment = 1)
    {
        if (!is_readable($font)) {
            throw new ImageUtilException('Error: The specified font not found');
        }

        if (!is_array($rgbAr)) {
            $rgbAr = [0, 0, 0];
        }

        $color = imagecolorallocate($this->image, $rgbAr[0], $rgbAr[1], $rgbAr[2]);

        // Determine the line break if required.
        if (($maxwidth > 0) && ($angle == 0)) {
            $words = explode(' ', $text);
            $lines = [$words[0]];
            $currentLine = 0;

            $numberOfWords = count($words);
            for ($i = 1; $i < $numberOfWords; $i++) {
                $lineSize = imagettfbbox($size, 0, $font, $lines[$currentLine] . ' ' . $words[$i]);
                if ($lineSize[2] - $lineSize[0] < $maxwidth) {
                    $lines[$currentLine] .= ' ' . $words[$i];
                } else {
                    $currentLine++;
                    $lines[$currentLine] = $words[$i];
                }
            }
        } else {
            $lines = [$text];
        }

        $curX = $point[0];
        $curY = $point[1];

        foreach ($lines as $text) {
            $bbox = imagettfbbox($size, $angle, $font, $text);

            switch ($textAlignment) {
                case TextAlignment::RIGHT:
                    $curX = $point[0] - abs($bbox[2] - $bbox[0]);
                    break;

                case TextAlignment::CENTER:
                    $curX = $point[0] - (abs($bbox[2] - $bbox[0]) / 2);
                    break;
            }

            imagettftext($this->image, $size, $angle, $curX, $curY, $color, $font, $text);

            $curY += ($size * 1.35);
        }
    }
public function writeText($text, $point, $size, $angle, $font, $maxwidth = 0, $rgbAr = null, $textAlignment = 1)
    {
        if (!is_readable($font)) {
            throw new ImageUtilException('Error: The specified font not found');
        }

        if (!is_array($rgbAr)) {
            $rgbAr = [0, 0, 0];
        }

        $color = imagecolorallocate($this->image, $rgbAr[0], $rgbAr[1], $rgbAr[2]);

        // Determine the line break if required.
        if (($maxwidth > 0) && ($angle == 0)) {
            $words = explode(' ', $text);
            $lines = [$words[0]];
            $currentLine = 0;

            $numberOfWords = count($words);
            for ($i = 1; $i < $numberOfWords; $i++) {
                $lineSize = imagettfbbox($size, 0, $font, $lines[$currentLine] . ' ' . $words[$i]);
                if ($lineSize[2] - $lineSize[0] < $maxwidth) {
                    $lines[$currentLine] .= ' ' . $words[$i];
                } else {
                    $currentLine++;
                    $lines[$currentLine] = $words[$i];
                }
            }
        } else {
            $lines = [$text];
        }

        $curX = $point[0];
        $curY = $point[1];

        foreach ($lines as $text) {
            $bbox = imagettfbbox($size, $angle, $font, $text);

            switch ($textAlignment) {
                case TextAlignment::RIGHT:
                    $curX = $point[0] - abs($bbox[2] - $bbox[0]);
                    break;

                case TextAlignment::CENTER:
                    $curX = $point[0] - (abs($bbox[2] - $bbox[0]) / 2);
                    break;
            }

            imagettftext($this->image, $size, $angle, $curX, $curY, $color, $font, $text);

            $curY += ($size * 1.35);
        }
    }
public function writeText ( $ text , $ point , $ size , $ angle , $ font , $ maxwidth = 0 , $ rgbAr = null , $ textAlignment = 1 ) { if ( ! is_readable ( $ font ) ) { throw new ImageUtilException ( 'Error: The specified font not found' ) ; } if ( ! is_array ( $ rgbAr ) ) { $ rgbAr = [ 0 , 0 , 0 ] ; } $ color = imagecolorallocate ( $ this -> image , $ rgbAr [ 0 ] , $ rgbAr [ 1 ] , $ rgbAr [ 2 ] ) ; // Determine the line break if required. if ( ( $ maxwidth > 0 ) && ( $ angle == 0 ) ) { $ words = explode ( ' ' , $ text ) ; $ lines = [ $ words [ 0 ] ] ; $ currentLine = 0 ; $ numberOfWords = count ( $ words ) ; for ( $ i = 1 ; $ i < $ numberOfWords ; $ i ++ ) { $ lineSize = imagettfbbox ( $ size , 0 , $ font , $ lines [ $ currentLine ] . ' ' . $ words [ $ i ] ) ; if ( $ lineSize [ 2 ] - $ lineSize [ 0 ] < $ maxwidth ) { $ lines [ $ currentLine ] .= ' ' . $ words [ $ i ] ; } else { $ currentLine ++ ; $ lines [ $ currentLine ] = $ words [ $ i ] ; } } } else { $ lines = [ $ text ] ; } $ curX = $ point [ 0 ] ; $ curY = $ point [ 1 ] ; foreach ( $ lines as $ text ) { $ bbox = imagettfbbox ( $ size , $ angle , $ font , $ text ) ; switch ( $ textAlignment ) { case TextAlignment :: RIGHT : $ curX = $ point [ 0 ] - abs ( $ bbox [ 2 ] - $ bbox [ 0 ] ) ; break ; case TextAlignment :: CENTER : $ curX = $ point [ 0 ] - ( abs ( $ bbox [ 2 ] - $ bbox [ 0 ] ) / 2 ) ; break ; } imagettftext ( $ this -> image , $ size , $ angle , $ curX , $ curY , $ color , $ font , $ text ) ; $ curY += ( $ size * 1.35 ) ; } }
Writes a text on the image.

@param string $text
@param float[] $point
@param float $size
@param float $angle
@param string $font
@param int $maxwidth
@param float[] $rgbAr
@param int $textAlignment
@throws ImageUtilException
Writes a text on the image .