Author Topic: Larger Font size for Captcha  (Read 15927 times)

0 Members and 1 Guest are viewing this topic.

shwekhaw

  • Full Member
  • ***
  • Posts: 7
Larger Font size for Captcha
« on: November 29, 2014, 09:14:21 PM »
We have been getting increasing amount of spam bots recently so we have to put up Captcha. But the problem is real visitors are having trouble reading small fonts. I looked at captcha.php in libs folder. ImageString function has font size 5 as largest limit which is not large enough. I tried using imagettftext function and it does not work (don't know why. according to phpinfo, freetype library is enabled). Is there work around this to make the security code string larger (like using a function to enlarge the whole image?)

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 951
    • Mibew Messenger
Re: Larger Font size for Captcha
« Reply #1 on: November 30, 2014, 11:41:17 PM »
What do you mean by "freetype library"? imagettftext function is a part of GD library. You'd better provide the appropriate parts of your phpinfo() output.

And how did you used imagettftext function? Show us the code.

As for the zooming an image. Personally I think that it's a terrible idea. However, have you tried to search in the PHP documentation? What about this function?

shwekhaw

  • Full Member
  • ***
  • Posts: 7
Re: Larger Font size for Captcha
« Reply #2 on: November 30, 2014, 11:59:44 PM »
Quote from php.net on imagettftext
Quote
Note:
This function requires both the GD library and the ยป FreeType library.

Here is phpinfo
GD Support   enabled
GD Version   bundled (2.0.34 compatible)
FreeType Support   enabled
FreeType Linkage   with freetype
FreeType Version   2.3.11
T1Lib Support   enabled
GIF Read Support   enabled
GIF Create Support   enabled
JPEG Support   enabled
libJPEG Version   6b
PNG Support   enabled
libPNG Version   1.2.39
WBMP Support   enabled
XPM Support   enabled
XBM Support   enabled

Here is how I modify the code.

Code: [Select]

        $font = 'arial.ttf';
//     ImageString($image, 5, 30, 4, $security_code, $white);
imagettftext($image, 20, 0, 10, 20, $white, $font, $security_code);

I will try imagecopyresampled function.

shwekhaw

  • Full Member
  • ***
  • Posts: 7
Re: Larger Font size for Captcha
« Reply #3 on: December 01, 2014, 12:41:46 AM »
I made it work with imagecopyresampled function. Text looks little rough like zoom in effect. But it is readable.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 951
    • Mibew Messenger
Re: Larger Font size for Captcha
« Reply #4 on: December 01, 2014, 07:35:19 AM »
Talking about imagettftext function. I don't know what you meant by "does not work", since you haven't provided any messages from error logs and haven't described any symptoms.

But I suspect that your arial.ttf file is either inaccessible (maybe you should have used the full path) or broken. (BTW, don't forget that fonts should be used according to their licenses...)

shwekhaw

  • Full Member
  • ***
  • Posts: 7
Re: Larger Font size for Captcha
« Reply #5 on: December 01, 2014, 08:30:00 AM »
Strangely there is nothing in error log. I run test script mentioned in php.net and browser said the image cannot be displayed because it contains  error. All ttf files are in same folder as captcha.php (libs folder). I got them from under Win 7 as well my raspberry pi running wheezy.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 951
    • Mibew Messenger
Re: Larger Font size for Captcha
« Reply #6 on: December 01, 2014, 12:17:11 PM »
Strangely there is nothing in error log.

Then your server settings probably prevents PHP warnings from appearing in error logs.

All ttf files are in same folder as captcha.php (libs folder).

And what makes you think that the script from root directory will find the font file without full path?  ::)

Try this:

Code: [Select]
$font = dirname(__FILE__) . '/arial.ttf';

shwekhaw

  • Full Member
  • ***
  • Posts: 7
Re: Larger Font size for Captcha
« Reply #7 on: December 01, 2014, 04:43:36 PM »
Sever is reporting other php errors in log file so I am assuming error is not with php. I am using example 1 at http://php.net/manual/en/function.imagettftext.php. Full path does not work either. I think the problem is with font file. I am not familiar with installing font in linux system. Do I need to install font to the system like in Windows or just copying should work?

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 951
    • Mibew Messenger
Re: Larger Font size for Captcha
« Reply #8 on: December 02, 2014, 02:09:34 PM »
Do I need to install font to the system like in Windows or just copying should work?

A TTF font is just a file. So copying should be enough.

At the same time, I don't think that this problem is somehow related to Mibew Messenger. It looks more like a problem with PHP and/or some of its libraries. Or a problem with the font. Or with the environment (for example, with some system limits and/or insufficient system resources). As a matter of fact, I can only stare into a crystal ball and make abstract guesses.

shwekhaw

  • Full Member
  • ***
  • Posts: 7
Re: Larger Font size for Captcha
« Reply #9 on: December 03, 2014, 03:39:50 AM »
Thanks. For now imagecopyresampled does the job.