SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to replace Captcha Library

    I would like to replace a captcha library.php script with another one that is readable or make the background not so dark and I'd like the font smaller. I tried to make it smaller but it defaulted back to original size.

    any suggestions..?


    PHP Code:
    <?php
    session_start
    ();

    /*
    * File: CaptchaSecurityImages.php
    * Author: Simon Jarvis
    * Copyright: 2006 Simon Jarvis
    * Date: 03/08/06
    * Updated: 07/02/07
    * Requirements: PHP 4/5 with GD and FreeType libraries
    * Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php

    * This program is free software; you can redistribute it and/or 
    * modify it under the terms of the GNU General Public License 
    * as published by the Free Software Foundation; either version 2 
    * of the License, or (at your option) any later version.

    * This program is distributed in the hope that it will be useful, 
    * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    * GNU General Public License for more details: 
    * http://www.gnu.org/licenses/gpl.html
    *
    */

    class CaptchaSecurityImages {

        var 
    $font 'monofont.ttf';

        function 
    generateCode($characters) {
            
    /* list all possible characters, similar looking characters and vowels have been removed */
            
    $possible '23456789bcdfghjkmnpqrstvwxyz';
            
    $code '';
            
    $i 0;
            while (
    $i $characters) { 
                
    $code .= substr($possiblemt_rand(0strlen($possible)-1), 1);
                
    $i++;
            }
            return 
    $code;
        }

        function 
    CaptchaSecurityImages($width='120',$height='40',$characters='6') {
            
    $code $this->generateCode($characters);
            
    /* font size will be 80% of the image height */
            
    $font_size $height 0.80;
            
    $image = @imagecreate($width$height) or die('Cannot initialize new GD image stream');
            
    /* set the colours */
            
    $background_color imagecolorallocate($image255255255);
            
    $text_color imagecolorallocate($image2040100);
            
    $noise_color imagecolorallocate($image100120180);
            
    /* generate random dots in background */
            
    for( $i=0$i<($width*$height)/3$i++ ) {
                
    imagefilledellipse($imagemt_rand(0,$width), mt_rand(0,$height), 11$noise_color);
            }
            
    /* generate random lines in background */
            
    for( $i=0$i<($width*$height)/150$i++ ) {
                
    imageline($imagemt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
            }
            
    /* create textbox and add text */
            
    $textbox imagettfbbox($font_size0$this->font$code) or die('Error in imagettfbbox function');
            
    $x = ($width $textbox[4])/2;
            
    $y = ($height $textbox[5])/2;
            
    imagettftext($image$font_size0$x$y$text_color$this->font $code) or die('Error in imagettftext function');
            
    /* output captcha image to browser */
            
    header('Content-Type: image/jpeg');
            
    imagejpeg($image);
            
    imagedestroy($image);
            
    $_SESSION['security_code'] = $code;
        }

    }

    $width = isset($_GET['width']) ? $_GET['width'] : '120';
    $height = isset($_GET['height']) ? $_GET['height'] : '40';
    $characters = isset($_GET['characters']) && $_GET['characters'] > $_GET['characters'] : '6';

    $captcha = new CaptchaSecurityImages($width,$height,$characters);

    ?>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    modifying CAPTCHA

    It looks like the font size is determined by
    PHP Code:
    $font_size $height 0.80
    try changing the "0.80" to other values keeping in mind that it's a percentage of the image height.
    PHP Code:
    var $font 'monofont.ttf'
    If you don't like this one, you could try another. I don't have any links off-hand, but there are sites that have free ttf fonts.
    Quote Originally Posted by lukkas
    background not so dark
    PHP Code:
    $background_color imagecolorallocate($image255255255); 
    AFAIK "255, 255, 255" is white. unless I've got it backwards and it's black (additive vs subtractive thing). You could try other values for those 3, making sure they're all the same if you want grey scale.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •