Ver Mensaje Individual
  #4 (permalink)  
Antiguo 31/05/2014, 17:15
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 1 mes
Puntos: 292
Respuesta: Alguien me explica como usar este codigo

Que pena leer tan mal!

Los colores estan codificados en RGB (red-green-blue) asi que cada vez que ves: $color1, $color2, $color3 estas viendo la cantidad de rojo, verde y azul y que como te explico mejor al final son el la practica esos grises horribles.

Ten en cuenta que el bajo contraste tiene que ver con hacer mas dificil la decodificacion via algortimos de reconocimiento de caracteres, pero bueno aca un cambio ... luego si tengo tiempo lo mejoro haciendo puedas cojer entre varios colores pre-seleccionados de un array con array_rand() ..bla bla bla

Código PHP:
Ver original
  1. <?php  
  2.  
  3.      
  4.     #create image and set background color
  5.    $captcha = imagecreatetruecolor(120,35);
  6.     $background_color = imagecolorallocate($captcha, 0xff, 0xff, 0xff); //fffff = 255
  7.     imagefill($captcha, 0, 0, $background_color);
  8.      
  9.     #draw some lines
  10.    for($i=0;$i<10;$i++){
  11.         imageline($captcha, rand(0,130),rand(0,35), rand(0,130), rand(0,35),imagecolorallocate($captcha, 0x33, 0xff, 0x00)); //33ff00 = es un verde claro
  12.     }
  13.      
  14.     #generate a random string of 5 characters
  15.    $string = substr(md5(rand()*time()),0,5);
  16.  
  17.     #make string uppercase and replace "O" and "0" to avoid mistakes
  18.    $string = strtoupper($string);
  19.     $string = str_replace("O","B", $string);
  20.     $string = str_replace("0","C", $string);
  21.  
  22.     #save string in session "captcha" key
  23.    session_start();
  24.     $_SESSION["captcha"]=$string;
  25.    
  26.  
  27.     #place each character in a random position
  28.    putenv('GDFONTPATH=' . realpath('.'));
  29.     $font = 'arial.ttf';
  30.     for($i=0;$i<5;$i++){        
  31.         if(file_exists($font)){
  32.             $x=4+$i*23+rand(0,6);
  33.             $y=rand(18,28);
  34.             imagettftext  ($captcha, 15, rand(-25,25), $x, $y, imagecolorallocate($captcha, 0x00, 0x33, 0x66), $font, $string[$i]);
  35.         }else{
  36.             $x=5+$i*24+rand(0,6);
  37.             $y=rand(1,18);
  38.             imagestring($captcha, 5, $x, $y, $string[$i], imagecolorallocate($captcha, 0x00, 0x33, 0x66));
  39.         }
  40.     }
  41.      
  42.     #applies distorsion to image
  43.    $matrix = array(array(1, 1, 1), array(1.0, 7, 1.0), array(1, 1, 1));
  44.     imageconvolution($captcha, $matrix, 16, 32);
  45.  
  46.     #avoids catching
  47.    header("Expires: 0");
  48.     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  49.     header("Cache-Control: private",false);  
  50.  
  51.     #return the image
  52.    header("Content-type: image/gif");
  53.     imagejpeg($captcha);
  54. ?>

Basicamente elimine esos $color, $color, $color que te daban siempre grises (porque R == G == B son grises) y le puse unos que me gustaron que coji de esta tabla RGB


PD: el post anterior mio.... denota estaba en las nubes...... jejeje
__________________
Salu2!

Última edición por Italico76; 31/05/2014 a las 17:35