Does anyone off hand know how to change the font types and font sizes used by the captcha module? The letters are too small for my taste and I'd like a new font. I have loaded a new font and it's path in the configuration a few times. No dice. Any ideas?

thanks,
Wim

Comments

wulff’s picture

In my test setup I use Vera Sans and Vera Serif for the captchas.

I created the directory d:\wwwroot\drupal\fonts and copied the files vera.ttf and verase.ttf to the new directory.

On the captcha settings screen in Drupal I have 'True Type Fonts Path' set to d:/wwwroot/drupal/fonts

After saving the settings 'Image and font information' shows:

Number of fonts found: 2
GD Version: bundled (2.0.28 compatible)
FreeType Support: True

To change the font size, edit the value of the variable $charSize in the _captcha_image() function in captcha.module. You have to modify the image size and the initial value of $y as well. My settings for a 48pt font are:

$im = imagecreatetruecolor(320, 160);
$charSize = 48;
$y = 60;

(Although a width of 320 still results in some clipping every now and then.)

skor’s picture

The path you entered appears to be an ablsolute path (on a windows pc?). I'm on a shared server, so I found out what my absoulute path is on the linux server and tried that, but got an error saying it couldn't be found.

I've also tried the path relative to my drupal install, and relative to my httdoc root. Still no joy. Any ideas?

gecko13’s picture

The message I get is the same...

The current font path is invalid. The default font will be used.

I have also tried the absolute path and this did not work.

helsinki’s picture

It's quite old this post, but just for the record, type fonts in the font path and that works fine.

__________________
http://www.wilba.org

battochir’s picture

Hei Helsinki,

Yes it's old but I still follow them! Thanks.

Kitos,

wim

helsinki’s picture

ei mitään ;-)

__________________
http://www.wilba.org

loloyd’s picture

I'm using Drupal 4.7.0 but I guess this also works for captcha for version 4.6.x as well. I had installed my fonts in the directory "D:\websites\home\fonts\". Note that my Drupal directory is "D:\websites\home\" - this info is important.

I had a persistent path not found error. I initially set it to "/fonts". No dice.
Then I set it to "fonts". No dice again.
Set it to "D:\websites\home\fonts\". No dice still.
Searched Drupal site. They said absolute directory reference "D:\websites\home\fonts\" should work. And even also just "fonts".
Retried both. Still didn't work. Then I noticed that the path not found error was looking at "/font" still - notice that I've already changed it to "D:\websites\home\fonts\" or "fonts". So I THEN created a directory "D:\fonts\" temporarily. Retried both "D:\websites\home\fonts\" and just "fonts" and now they work. Now I can remove the "D:\fonts\".

It appears that the captcha module kept looking for "/fonts" at the beginning of its code even though I have changed from it already

Faultless, huh?

rantenki’s picture

Change the top of the captcha_settings function (line 45) in modules/captcha/captcha.module to have this instead of the existing code:

function captcha_settings() {
[............. some other code is here already
    //check for TTF support
    $fontPath=variable_get("captcha_fonts_path", "");
    if (!function_exists(imagettftext))
      drupal_set_message(t('Your image library does not seem to have TrueType font support. Captcha will work, but will use the default inbuilt font.'),'status');
    else {
      //check for valid font path
      if ((variable_get("captcha_fonts_path", "")!='')&& !is_dir(variable_get("captcha_fonts_path", "misc/"))){
        variable_set("captcha_fonts_path","");
        form_set_error('Invalid font path', t('The current font path is invalid. The default font will be used.'));
      }
    }
  }
............ the rest of the function is after this...]
[then change this line:]
  $form['captcha_fonts_path'] = array(
                                  '#type' => 'textfield',
                                  '#title' => t('TrueType Fonts Path'),
                                  '#default_value' => ###THIS HAS SOMETHING BUT CHANGE IT TO $fontPath ######,
                                  '#size' => 30,
                                  '#maxlength' => 255,
                                  '#description' => t('Location of the directory where the Truetype (.ttf) fonts are stored. If you do not provide any fonts, the module will use the default font for text.'),
                                );

This repairs the rather odd settings method that causes Drupal to remember the OLD settings (basically it will read the OLD variable before the new one is set, resulting in a broken setting that can never be changed). This code directly resets the captcha path variable in order to "forget" the bad setting. No other changes in the module are needed.