src/Leevel/Seccode/Seccode.php
protected function makeTtfFont(&$resImage): void
    {
        if (!function_exists('imagettftext')) {
            // @codeCoverageIgnoreStart
            throw new InvalidArgumentException('Function imagettftext is not exits.');
            // @codeCoverageIgnoreEnd
        }

        list($font, $code, $widthTotal) = $this->getFontOption();

        $width = $this->normalizeWidth();
        $height = $this->normalizeHeight();

        // deg2rad() 函数将角度转换为弧度 cos 是 cosine 的简写
        // 表示余弦函数
        $x = $this->mtRand(
            $font[0]['tilt'] > 0 ?
                cos(deg2rad(90 - $font[0]['tilt'])) * $font[0]['zheight'] :
                1,
            $width - $widthTotal
        );

        // 是否启用随机颜色
        if (!$this->option['color']) {
            $resTextColor = imagecolorallocate(
                $resImage,
                $this->fontColor[0],
                $this->fontColor[1],
                $this->fontColor[2]
            );
        }

        for ($i = 0; $i < count($font); $i++) {
            if ($this->option['color']) {
                $this->fontColor = [
                    $this->mtRand(0, 255),
                    $this->mtRand(0, 255),
                    $this->mtRand(0, 255),
                ];

                $resTextColor = imagecolorallocate(
                    $resImage,
                    $this->fontColor[0],
                    $this->fontColor[1],
                    $this->fontColor[2]
                );
            }

            if ($this->option['shadow']) {
                $resTextShadowColor = imagecolorallocate(
                    $resImage,
                    255 - $this->fontColor[0],
                    255 - $this->fontColor[1],
                    255 - $this->fontColor[2]
                );
            }

            $y = $font[0]['tilt'] > 0 ?
                $this->mtRand(
                    $font[$i]['height'],
                    $height
                ) :
                $this->mtRand(
                    $font[$i]['height'] - $font[$i]['hd'],
                    $height - $font[$i]['hd']
                );

            if ($this->option['shadow']) {
                imagettftext($resImage,
                    $font[$i]['size'],
                    $font[$i]['tilt'],
                    (int) ($x + 1),
                    (int) ($y + 1),
                    $resTextShadowColor,
                    $font[$i]['font'],
                    $code[$i]
                );
            }

            imagettftext($resImage,
                $font[$i]['size'],
                $font[$i]['tilt'],
                (int) ($x),
                (int) ($y),
                $resTextColor,
                $font[$i]['font'],
                $code[$i]
            );

            $x += $font[$i]['width'];
        }
    }
protected function makeTtfFont(&$resImage): void
    {
        if (!function_exists('imagettftext')) {
            // @codeCoverageIgnoreStart
            throw new InvalidArgumentException('Function imagettftext is not exits.');
            // @codeCoverageIgnoreEnd
        }

        list($font, $code, $widthTotal) = $this->getFontOption();

        $width = $this->normalizeWidth();
        $height = $this->normalizeHeight();

        // deg2rad() 函数将角度转换为弧度 cos 是 cosine 的简写
        // 表示余弦函数
        $x = $this->mtRand(
            $font[0]['tilt'] > 0 ?
                cos(deg2rad(90 - $font[0]['tilt'])) * $font[0]['zheight'] :
                1,
            $width - $widthTotal
        );

        // 是否启用随机颜色
        if (!$this->option['color']) {
            $resTextColor = imagecolorallocate(
                $resImage,
                $this->fontColor[0],
                $this->fontColor[1],
                $this->fontColor[2]
            );
        }

        for ($i = 0; $i < count($font); $i++) {
            if ($this->option['color']) {
                $this->fontColor = [
                    $this->mtRand(0, 255),
                    $this->mtRand(0, 255),
                    $this->mtRand(0, 255),
                ];

                $resTextColor = imagecolorallocate(
                    $resImage,
                    $this->fontColor[0],
                    $this->fontColor[1],
                    $this->fontColor[2]
                );
            }

            if ($this->option['shadow']) {
                $resTextShadowColor = imagecolorallocate(
                    $resImage,
                    255 - $this->fontColor[0],
                    255 - $this->fontColor[1],
                    255 - $this->fontColor[2]
                );
            }

            $y = $font[0]['tilt'] > 0 ?
                $this->mtRand(
                    $font[$i]['height'],
                    $height
                ) :
                $this->mtRand(
                    $font[$i]['height'] - $font[$i]['hd'],
                    $height - $font[$i]['hd']
                );

            if ($this->option['shadow']) {
                imagettftext($resImage,
                    $font[$i]['size'],
                    $font[$i]['tilt'],
                    (int) ($x + 1),
                    (int) ($y + 1),
                    $resTextShadowColor,
                    $font[$i]['font'],
                    $code[$i]
                );
            }

            imagettftext($resImage,
                $font[$i]['size'],
                $font[$i]['tilt'],
                (int) ($x),
                (int) ($y),
                $resTextColor,
                $font[$i]['font'],
                $code[$i]
            );

            $x += $font[$i]['width'];
        }
    }
创建字体信息.

@param resource $resImage