I ran page speed against my site which is running image captcha. It said that to increase rendering speed image dimensions should be used.

http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyImage...

I don't know if Captcha uses a fixed image size or not, I wasn't able to find an image size value in the settings.

I have attached a patch specifying the sizes which I believe to be static.

Comments

elachlan’s picture

Status: Needs review » Needs work

On closer inspection I found that the code length changes the width.

I see the $code_length attribute in image_captcha.module line 207

The change would be at line 223.

I was thinking something along the lines of:

<?php
'#markup' => '<img src="' . $img_src . '" width="' . ($code_length * 18)  . '" height="36" alt="' . t('Image CAPTCHA') . '" title="' . t('Image CAPTCHA') . '" />',
?>

I tested it and it doesn't work. Not sure how to fix it. I think I have to make sure $code_length is an int then convert both back to a string.

soxofaan’s picture

Category: bug » feature
Issue tags: +low-hanging fruit

Good idea, but hardly a bug, more a feature request.

Anyway, this is the code that defines the image size (see function _image_captcha_generate_image in image_captcha.user.inc:

  $font_size = (int) variable_get('image_captcha_font_size', 30);
  $character_spacing = (float) variable_get('image_captcha_character_spacing', '1.2');
  $characters = _image_captcha_utf8_split($code);
  $character_quantity = count($characters);
  $width = $character_spacing * $font_size * $character_quantity;
  $height = 2 * $font_size;

  // create image resource
  $image = imagecreatetruecolor($width, $height);

For this issue, I would recommend to factor this code out in a function like image_captcha_image_size() and then use this function in _image_captcha_generate_image() and in image_captcha_captcha()

elachlan’s picture

Status: Needs work » Needs review
StatusFileSize
new2.68 KB

Patch with changes.

soxofaan’s picture

Status: Needs review » Needs work

that's fast :)

I didn't try the patch yet (only read it), but here is just a tip to make the code cleaner:

function image_captcha_image_size() {
  //....
  return array($width, $height);
}

// ...
list($width, $height) = image_captcha_image_size();

Also, the patch seems to introduces tab instead of spaces for indentation in image_captcha.module.

elachlan’s picture

Status: Needs work » Needs review
StatusFileSize
new2.89 KB

Changes :)

Hopefully fixed!!

soxofaan’s picture

thanks for the update.

some remarks
in image_captcha_image_size:
- $fonts = _image_captcha_get_enabled_fonts(); is not needed I think
- $code is used but not defined, there must be something wrong here.

in _image_captcha_generate_image: still using $arr['width'] instead of list(width, ...)

elachlan’s picture

StatusFileSize
new3 KB

Hopefully Fixed!!!

Changes it so that it requires the $Code parameter.

The code needs better comments, its hard to understand some of it.

soxofaan’s picture

Status: Needs review » Fixed

Hi elachlan,

I reworked your patch a bit: renamed to function "_image_captcha_image_size" (with leading underscore), moved it to image_captcha.module (from image_captcha.user.inc) and added a bit more documentation.

Committed: http://drupal.org/cvs?commit=456624

thanks for your work

elachlan’s picture

Love your work soxofaan! Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -low-hanging fruit

Automatically closed -- issue fixed for 2 weeks with no activity.