SlightPHP\SimpleCaptcha::WriteText PHP Method

WriteText() protected method

Text insertion
protected WriteText ( $text, $fontcfg = [] )
    protected function WriteText($text, $fontcfg = array())
    {
        if (empty($fontcfg)) {
            // Select the font configuration
            $fontcfg = $this->fonts[array_rand($this->fonts)];
        }
        $fontfile = dirname(__FILE__) . '/fonts/' . $fontcfg['font'];
        /** Increase font-size for shortest words: 9% for each glyp missing */
        $lettersMissing = $this->maxWordLength - strlen($text);
        $fontSizefactor = 1 + $lettersMissing * 0.09;
        // Text generation (char by char)
        $x = 20 * $this->scale;
        $y = round($this->height * 27 / 40 * $this->scale);
        $length = strlen($text);
        for ($i = 0; $i < $length; $i++) {
            $degree = rand($this->maxRotation * -1, $this->maxRotation);
            $fontsize = rand($fontcfg['minSize'], $fontcfg['maxSize']) * $this->scale * $fontSizefactor;
            $letter = substr($text, $i, 1);
            if ($this->shadowColor) {
                $coords = imagettftext($this->im, $fontsize, $degree, $x + $this->scale, $y + $this->scale, $this->GdShadowColor, $fontfile, $letter);
            }
            $coords = imagettftext($this->im, $fontsize, $degree, $x, $y, $this->GdFgColor, $fontfile, $letter);
            $x += $coords[2] - $x + $fontcfg['spacing'] * $this->scale;
        }
    }