Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/05/2014, 16:18
Avatar de thepiratebyte
thepiratebyte
 
Fecha de Ingreso: mayo-2014
Mensajes: 13
Antigüedad: 10 años
Puntos: 0
Pregunta Alguien me explica como usar este codigo

Baje es te codigo de captcha facil. es un captcha en PHP con una imagen gris de fondo y letras y numeros en gris oscuro.

Lo que quiero es que las letras y numeros sean de colores y el fondo distinto para que no sea tan opaco y mas variado.
nose si se puede lograr con estos codigos. creo que son los rand. pero no entiendo mucho. solo quiero cambiar las letras de color. que aparescan una de cada color

Código PHP:

<?php 

    
    
#create image and set background color
    
$captcha imagecreatetruecolor(120,35);
    
$color rand(128,160);
    
$background_color imagecolorallocate($captcha$color$color$color);
    
imagefill($captcha00$background_color);
    
    
#draw some lines
    
for($i=0;$i<10;$i++){
        
$color rand(48,96);
        
imageline($captcharand(0,130),rand(0,35), rand(0,130), rand(0,35),imagecolorallocate($captcha$color$color$color));
    }
    
    
#generate a random string of 5 characters
    
$string substr(md5(rand()*time()),0,5);

    
#make string uppercase and replace "O" and "0" to avoid mistakes
    
$string strtoupper($string);
    
$string str_replace("O","B"$string);
    
$string str_replace("0","C"$string);

    
#save string in session "captcha" key
    
session_start();
    
$_SESSION["captcha"]=$string;

    
#place each character in a random position
    
putenv('GDFONTPATH=' realpath('.'));
    
$font 'arial.ttf';
    for(
$i=0;$i<5;$i++){
        
$color rand(0,32);
        if(
file_exists($font)){
            
$x=4+$i*23+rand(0,6);
            
$y=rand(18,28);
            
imagettftext  ($captcha15rand(-25,25), $x$yimagecolorallocate($captcha$color$color$color), $font$string[$i]);
        }else{
            
$x=5+$i*24+rand(0,6);
            
$y=rand(1,18);
            
imagestring($captcha5$x$y$string[$i], imagecolorallocate($captcha$color$color$color));
        }
    }
    
    
#applies distorsion to image
    
$matrix = array(array(111), array(1.071.0), array(111));
    
imageconvolution($captcha$matrix1632);

    
#avoids catching
    
header("Expires: 0");
    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
header("Cache-Control: private",false); 

    
#return the image
    
header("Content-type: image/gif");
    
imagejpeg($captcha);
?>

Última edición por thepiratebyte; 31/05/2014 a las 16:22 Razón: titulo confuso