Amiro.CMS API Reference
Amiro.Ru / Manual
Loading search...

The AMI_CaptchaImage class

• Introduction

Captcha image generator class.

• Class synopsis

AMI_CaptchaImage implements AMI_iCaptchaImage {
/* Properties */
// Custiom generator options
protected array $aOptions = array();
// Array containig supported image types
protected array $aSupportedImageTypes = array('png', 'gif', 'jpg', 'wbmp');
// GDLib installed flag
protected bool $bGDLibIsInstalled;
// Current symbols set: AMI_iCaptcha::CHARSET_DIGITS, AMI_iCaptcha::CHARSET_LETTERS, AMI_iCaptcha::CHARSET_LETTERS|AMI_iCaptcha::CHARSET_DIGITS
protected int $charset;
// Final image height
protected int $currentHeight;
// Final image width
protected int $currentWidth;
// Default image type
protected string $defaultImageType = 'png';
// Image string to display
protected string $imageString = '0';
// Current image type ('png','jpg',...)
protected string $imageType;
// Number of symbols in image
protected int $numSymbols;
// Current GD image object
protected object $oImage;
/* Methods */
// Constructor.
public __construct ( [ int $numSymbols = 4 ], [ string $charset = AMI_iCaptcha::CHARSET_DIGITS ] ) returns AMI_CaptchaImage;
// Main class function.
public createImage ( [ string $imageType = '' ], [ string $imageString = '' ] ) returns object Image;
// Generates random string for image.
public generateRandomImageString ( [ string $charset = 0 ] ) returns string;
// Getting custom option.
public getGenerateOption ( string $name ) returns mixed;
// Returns image object.
public getImage ( ) returns object.;
// Returns image string.
public getImageString ( ) returns string;
// Converting hex string into RGB values.
public hex2rgb ( [ string $hexVal = '' ] ) returns array;
// Returns is GD lib installed or not.
public isGDLibInstalled ( ) returns bool;
// Output current image to output stream.
public outToStream ( ) returns bool;
// Setting custom option.
public setGenerateOption ( string $name, string $value ) returns void;
// Setting string of symbols to generate image.
public setImageString ( string $string ) returns void;
// Setting number of symbols in image.
public setNumSymbols ( [ int $numSymbols = 4 ] ) returns void;
// Modify current image by wave deformation.
protected addWave ( [ object $img = null ] ) returns object Image;
// Checking on supported images types in current version of php graphics library.
protected checkSupportedTypes ( string $type ) returns bool;
}

• Class Details

  Example:
  •  // Customization: Adding zoom.
  •  // Add into '_local/common_functions.php':
  •  
  •  class NewCaptchaImage extends AMI_CaptchaImage{
  •          public function createImage($imageType ''$imageString ''){
  •              $oImage parent::createImage($imageType$imageString);
  •              $this->currentWidth imagesx($oImage);
  •              $this->currentHeight imagesy($oImage);
  •              $zoom 1.5;
  •              $oImage2 imagecreatetruecolor($this->currentWidth $zoom$this->currentHeight $zoom);
  •              imagecopyresampled(
  •                  $oImage2$oImage0000,
  •                  $this->currentWidth $zoom$this->currentHeight $zoom,
  •                  $this->currentWidth$this->currentHeight
  •              );
  •              $this->oImage $oImage2;
  •              return $this->image;
  •          }
  •  }
  •  AMI::addResource('captcha/image''NewCaptchaImage');
Tags:
resource captcha/image AMI::getResource('captcha/image')
since 5.12.0

• Class Properies

protected array $aOptions

Custiom generator options

protected array $aSupportedImageTypes

Array containig supported image types

protected bool $bGDLibIsInstalled

GDLib installed flag

protected int $charset

Current symbols set: AMI_iCaptcha::CHARSET_DIGITS, AMI_iCaptcha::CHARSET_LETTERS, AMI_iCaptcha::CHARSET_LETTERS|AMI_iCaptcha::CHARSET_DIGITS

protected int $currentHeight

Final image height

protected int $currentWidth

Final image width

protected string $defaultImageType

Default image type

protected string $imageString

Image string to display

protected string $imageType

Current image type ('png','jpg',...)

protected int $numSymbols

Number of symbols in image

protected object $oImage

Current GD image object

• Class Methods

// Constructor.
public __construct ( [ int $numSymbols = 4 ], [ string $charset = AMI_iCaptcha::CHARSET_DIGITS ] ) returns AMI_CaptchaImage;
  • int $numSymbols
    How many symbols
  • string $charset
    Available constatns: AMI_iCaptcha::CHARSET_DIGITS, AMI_iCaptcha::CHARSET_LETTERS, AMI_iCaptcha::CHARSET_LETTERS|AMI_iCaptcha::CHARSET_DIGITS

Implementation of: AMI_iCaptchaImage::__construct().

Defines the default parameters and constants.
// Main class function.
public createImage ( [ string $imageType = '' ], [ string $imageString = '' ] ) returns object Image;
  • string $imageType
    Optional, type of image, this version supported types: 'png', 'gif', 'jpg', 'wbmp'
  • string $imageString
    Optional, the string, which will be drawn, if parameter is not given, then will be drawn random number

Implementation of: AMI_iCaptchaImage::createImage().

Generation and return the image.
// Generates random string for image.
public generateRandomImageString ( [ string $charset = 0 ] ) returns string;
  • string $charset
    Available constatns: AMI_iCaptcha::CHARSET_DIGITS, AMI_iCaptcha::CHARSET_LETTERS, AMI_iCaptcha::CHARSET_LETTERS|AMI_iCaptcha::CHARSET_DIGITS
// Getting custom option.
public getGenerateOption ( string $name ) returns mixed;
  • string $name
    Option name
// Returns image object.
public getImage ( ) returns object.;
// Returns image string.
public getImageString ( ) returns string;
// Converting hex string into RGB values.
public hex2rgb ( [ string $hexVal = '' ] ) returns array;
  • string $hexVal
    Hex string value
// Returns is GD lib installed or not.
public isGDLibInstalled ( ) returns bool;
// Output current image to output stream.
public outToStream ( ) returns bool;

Implementation of: AMI_iCaptchaImage::outToStream().

// Setting custom option.
public setGenerateOption ( string $name, string $value ) returns void;
  • string $name
    Option number
  • string $value
    Variable value
// Setting string of symbols to generate image.
public setImageString ( string $string ) returns void;
  • string $string
    Available constatns: AMI_iCaptcha::CHARSET_DIGITS, AMI_iCaptcha::CHARSET_LETTERS, AMI_iCaptcha::CHARSET_LETTERS|AMI_iCaptcha::CHARSET_DIGITS
// Setting number of symbols in image.
public setNumSymbols ( [ int $numSymbols = 4 ] ) returns void;
  • int $numSymbols
    How many symbols
// Modify current image by wave deformation.
protected addWave ( [ object $img = null ] ) returns object Image;
  • object $img
    Image GD object
// Checking on supported images types in current version of php graphics library.
protected checkSupportedTypes ( string $type ) returns bool;
  • string $type
    Type of image, This version suppors types - 'png', 'gif', 'jpg', 'wbmp'.