You are here

function _image_captcha_image_size in CAPTCHA 8

Same name and namespace in other branches
  1. 7 image_captcha/image_captcha.module \_image_captcha_image_size()

Helper function for calculating image height and width.

They are based on given code and current font/spacing settings.

Parameters

string $code: The utf8 string which will be used to split in characters.

Return value

array [$width, $heigh].

2 calls to _image_captcha_image_size()
CaptchaImageResponse::generateImage in image_captcha/src/Response/CaptchaImageResponse.php
Base function for generating a image CAPTCHA.
image_captcha_captcha in image_captcha/image_captcha.module
Implements hook_captcha().

File

image_captcha/image_captcha.module, line 233
Implements image CAPTCHA for use with the CAPTCHA module.

Code

function _image_captcha_image_size($code) {
  $config = \Drupal::config('image_captcha.settings');
  $font_size = (int) $config
    ->get('image_captcha_font_size');
  $character_spacing = (double) $config
    ->get('image_captcha_character_spacing');
  $characters = _image_captcha_utf8_split($code);
  $character_quantity = count($characters);

  // Calculate height and width.
  $width = $character_spacing * $font_size * $character_quantity;
  $height = 2 * $font_size;
  return [
    $width,
    $height,
  ];
}