PhpCaptcha::DrawCharacters PHP Method

DrawCharacters() public method

public DrawCharacters ( )
    function DrawCharacters()
    {
        // loop through and write out selected number of characters
        for ($i = 0; $i < strlen($this->sCode); $i++) {
            // select random font
            $sCurrentFont = $this->aFonts[array_rand($this->aFonts)];
            // select random colour
            $minFontColor = $this->aFontColorRange[0];
            $maxFontColor = $this->aFontColorRange[1];
            if ($this->bUseColour) {
                $iTextColour = imagecolorallocate($this->oImage, rand($minFontColor, $maxFontColor), rand($minFontColor, $maxFontColor), rand($minFontColor, $maxFontColor));
                if ($this->bCharShadow) {
                    // shadow colour
                    $iShadowColour = imagecolorallocate($this->oImage, rand($minFontColor, $maxFontColor), rand($minFontColor, $maxFontColor), rand($minFontColor, $maxFontColor));
                }
            } else {
                $iRandColour = rand($minFontColor, $maxFontColor);
                $iTextColour = imagecolorallocate($this->oImage, $iRandColour, $iRandColour, $iRandColour);
                if ($this->bCharShadow) {
                    // shadow colour
                    $iRandColour = rand($minFontColor, $maxFontColor);
                    $iShadowColour = imagecolorallocate($this->oImage, $iRandColour, $iRandColour, $iRandColour);
                }
            }
            // select random font size
            $iFontSize = rand($this->iMinFontSize, $this->iMaxFontSize);
            // select random angle
            $iAngle = rand(-30, 30);
            // get dimensions of character in selected font and text size
            $aCharDetails = imageftbbox($iFontSize, $iAngle, $sCurrentFont, $this->sCode[$i], array());
            // calculate character starting coordinates
            $iX = $this->iSpacing / 4 + $i * $this->iSpacing;
            $iCharHeight = $aCharDetails[2] - $aCharDetails[5];
            $iY = $this->iHeight / 2 + $iCharHeight / 4;
            // write text to image
            imagefttext($this->oImage, $iFontSize, $iAngle, $iX, $iY, $iTextColour, $sCurrentFont, $this->sCode[$i], array());
            if ($this->bCharShadow) {
                $iOffsetAngle = rand(-30, 30);
                $iRandOffsetX = rand(-5, 5);
                $iRandOffsetY = rand(-5, 5);
                imagefttext($this->oImage, $iFontSize, $iOffsetAngle, $iX + $iRandOffsetX, $iY + $iRandOffsetY, $iShadowColour, $sCurrentFont, $this->sCode[$i], array());
            }
        }
    }