Foros del Web » Programando para Internet » PHP »

¿Cómo poner lineas a un CAPTCHA?

Estas en el tema de ¿Cómo poner lineas a un CAPTCHA? en el foro de PHP en Foros del Web. Hola buenas tardes, he visto muchos captchas que tienen unas lineas por la imagen. Me gustaria poner de esas lineas a mi captcha aqui os ...
  #1 (permalink)  
Antiguo 09/05/2010, 08:39
 
Fecha de Ingreso: abril-2010
Mensajes: 9
Antigüedad: 14 años
Puntos: 0
¿Cómo poner lineas a un CAPTCHA?

Hola buenas tardes, he visto muchos captchas que tienen unas lineas por la imagen.

Me gustaria poner de esas lineas a mi captcha aqui os dejo los codigos:

Captcha_config.php

Código PHP:
<?php
// Captcha image generator configuration 

$background "images/imagecaptcha.gif"// this is the image used for random background creation

$sizex 167// captcha image width pixels
$sizey 50// captcha image height pixels
$lineas 4// Cantidad de lineas de relleno 

$yofs 3// VERTICAL text offset for font (varies with font) to get it 'just so'
$random 1// 1 is random rotation, 0 is no rotation

$length 6// number of characters in security code (must fit on your image!)

$font "Vrev.TTF";
$size 16// pixel size of the font used may need adjusting depending on your chosen font
$bold 1// 0=OFF. Some fonts/backgrounds will need bold text, so change $bold=0 to $bold=1

$red 225// RGB red channel 0-255 for font color
$green 225// RGB green channel 0-255 for font color
$blue 225// RGB blue channel 0-255 for font color
?>

Captcha_image.php

Código PHP:
<?php
session_start
();
include(
"captcha_config.php"); // file with configuration data

// create random character code for the captcha image
$text "";
$key_chars 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'
$rand_max  strlen($key_chars) - 1;
for (
$i 0$i $length$i++) {
    
$rand_pos  rand(0$rand_max);
    
$text.= $key_chars{$rand_pos};
}
$_SESSION['captcha'] = $text// save what we create

// center text in the 'box' regardless of rotation
function imagettftext_cr(&$img$size$angle$x$y$content_color$font$text) {
    
// retrieve boundingbox
    
$bbox imagettfbbox($size$angle$font$text);
    
// calculate deviation
    
$dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0// deviation left-right
    
$dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0// deviation top-bottom
    // new pivotpoint
    
$px $x-$dx;
    
$py $y-$dy;
    return 
imagettftext($img$size$angle$px$py$content_color$font$text);
}

// get background image dimensions
$imgsize getimagesize($background); 
$height $imgsize[1];
$width $imgsize[0];
$xmax $width $sizex;
$ymax $height $sizey;

// create the background in memory so we can grab chunks for each random image
$copy imagecreatefromgif($background);

// create the image
$img imagecreatetruecolor($sizex,$sizey);
$content_color imagecolorallocate($img$red$green$blue);     
    
// choose a random block (right size) of the background image
$x0 rand(0,$xmax); $x1 $x0 $sizex;
$y0 rand(0,$ymax); $y1 $y0 $sizey;

imagecopy($img,$copy00$x0$y0$x1$y1);
$angle $random * (5*rand(0,8) - 20); // random rotation -20 to +20 degrees

// add text to image once or twice (offset one pixel to emulate BOLD text if needed)
imagettftext_cr($img$size$angle$sizex/2$sizey/2-$yofs$content_color$font$text);
if (
$bold==1) {
    
imagettftext_cr($img$size$angle$sizex/2+1$sizey/2-$yofs$content_color$font$text);
}
header ("content-type: image/png");
imagepng ($img);
imagedestroy ($img);
?>

¿Que añado para tener esas lineas?
Gracias a todos los q me ayuden de antemano
  #2 (permalink)  
Antiguo 09/05/2010, 09:45
Avatar de DeveloperFresh  
Fecha de Ingreso: mayo-2009
Ubicación: Ancon City
Mensajes: 35
Antigüedad: 14 años, 11 meses
Puntos: 3
Respuesta: ¿Cómo poner lineas a un CAPTCHA?

Bueno para crear las lineas en un Captcha ! agregarias la funcion imageline

Código PHP:
Ver original
  1. <?php
  2. # la variable $im es el recurso de la imagen que es devuelvo por la funcion imagecreatetruecolor()
  3. # $x1 es la coordeanada x del primer punto
  4. # $y1 es la coordeanada y del primer punto
  5. # $x2 es la coordeanada x del segundo punto
  6. # $y2 es la coordeanada y del segundo punto
  7. # $color es el color de la  linea osea creado con la funcion  imagecolorallocate()
  8. imageline($im, $x1, $y1, $x2, $y2, $color);
  9.  
  10. ?>

Salu2
  #3 (permalink)  
Antiguo 10/05/2010, 07:18
 
Fecha de Ingreso: abril-2010
Mensajes: 9
Antigüedad: 14 años
Puntos: 0
Respuesta: ¿Cómo poner lineas a un CAPTCHA?

Cita:
Iniciado por DeveloperFresh Ver Mensaje
Bueno para crear las lineas en un Captcha ! agregarias la funcion imageline

Código PHP:
Ver original
  1. <?php
  2. # la variable $im es el recurso de la imagen que es devuelvo por la funcion imagecreatetruecolor()
  3. # $x1 es la coordeanada x del primer punto
  4. # $y1 es la coordeanada y del primer punto
  5. # $x2 es la coordeanada x del segundo punto
  6. # $y2 es la coordeanada y del segundo punto
  7. # $color es el color de la  linea osea creado con la funcion  imagecolorallocate()
  8. imageline($im, $x1, $y1, $x2, $y2, $color);
  9.  
  10. ?>

Salu2
he copiado y pegado eso y no me va mirad las lineas que yo quiero son algo asi:

http://www.mancera.org/2009/10/22/crear-sistema-de-captcha-en-php/

si vais al final de la pagina en donde sale lo de añadir un comentario hay un captcha con unas lineas con formas curvas y son lineas un poco anchas

como hago eso?
  #4 (permalink)  
Antiguo 10/05/2010, 07:27
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
Respuesta: ¿Cómo poner lineas a un CAPTCHA?

bueno creo que ya te han dicho la solucion... imageline()
para usarlo debes leer su forma de implementacion.. no se agregan magicamente ni nada

saludos!
__________________
More about me...
~ @rhyudek1
~ Github

Etiquetas: captcha, lineas, poner
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 23:35.