Source for file Figlet.php
Documentation is available at Figlet.php
* Require Figlet class for rendering the text.
require_once 'Text/CAPTCHA.php';
require_once 'Text/Figlet.php';
* Text_CAPTCHA_Driver_Figlet - Text_CAPTCHA driver Figlet based CAPTCHAs
* @license PHP License, version 3.0
* @author Aaron Wormus <wormus@php.net>
* @author Christian Wenz <wenz@php.net>
* @todo define an obfuscation algorithm
* Initializes the new Text_CAPTCHA_Driver_Figlet object and creates a GD image
* @param array $options CAPTCHA options
* @return mixed true upon success, PEAR error otherwise
function init($options = array ())
if (!empty ($options['output'])){
$this->_output = $options['output'];
if (isset ($options['width']) && is_int($options['width'])) {
$this->_width = $options['width'];
if (!empty ($options['length'])){
$this->_length = $options['length'];
if (!isset ($options['phrase']) || empty ($options['phrase'])) {
$this->_createPhrase ($this->_length);
$this->_phrase = $options['phrase'];
if (empty ($options['options']) || !is_array($options['options'])){
if (!empty ($options['options']['style']) && is_array($options['options']['style'])){
$this->_style = $options['options']['style'];
if (empty ($this->style['padding'])){
$this->_style['padding'] = '5px';
if (!empty ($options['options']['font_file'])){
if (is_array($options['options']['font_file'])){
$this->_font = $options['options']['font_file'][array_rand($options['options']['font_file'])];
$this->_font = $options['options']['font_file'];
* Create random CAPTCHA phrase
* This method creates a random phrase
$this->_phrase = Text_Password ::create ($this->_length);
* This method creates a CAPTCHA image
* @return void PEAR_Error on error
function _createCAPTCHA ()
$this->_fig = new Text_Figlet ();
if (PEAR ::isError ($this->_fig->LoadFont ($this->_font))){
$this->_error = PEAR ::raiseError ('Error loading Text_Figlet font');
$this->_output_string = $this->_fig->LineEcho ($this->_phrase);
* Return CAPTCHA in the specified format
* This method returns the CAPTCHA depending on the output format
* @return mixed Formatted captcha or PEAR error
$retval = $this->_createCAPTCHA ();
if (PEAR ::isError ($retval)) {
return PEAR ::raiseError ($retval->getMessage ());
switch ($this->_output) {
return $this->_output_string;
* This method returns the CAPTCHA as HTML
* @return mixed HTML Figlet image or PEAR error
$retval = $this->_createCAPTCHA ();
if (PEAR ::isError ($retval)) {
return PEAR ::raiseError ($retval->getMessage ());
$charwidth = strpos($this->_output_string, "\n");
$data = str_replace("\n", '<br />', $this->_output_string);
$textsize = ($this->_width / $charwidth) * 1.4;
foreach ($this->_style as $key => $value){
$css_output .= " $key: $value;";
$htmloutput = '<div style="font-family: courier;
font-size: '. $textsize. 'px;
width:'. $this->_width. 'px;
$htmloutput .= '<div style="'. $css_output. 'margin:0px;">
<pre style="padding: 0px; margin: 0px;">'. $data. '</pre></div></div>';
* Return CAPTCHA as Javascript version of HTML
* This method returns the CAPTCHA as a Javascript string
* I'm not exactly sure what the point of doing this would be.
* @return mixed javascript string or PEAR error
if (PEAR ::isError ($data)) {
return PEAR ::raiseError ($data->getMessage ());
$javascript = " <script language=\"javascript\">
document.write(unescape(\"$obfus_data.\" ) );
Documentation generated on Mon, 11 Mar 2019 14:44:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|