Version de GIFEncoder que utilizé PHPclasses / Pastie Bin.
Código (php) [Seleccionar]
<?php
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFEncoder Version 2.0 by László Zsidi, http://gifs.hu
::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/
include "GIFEncoder.class.php";
class Captcha
{
protected $captcha;
protected $clave;
function __construct()
{
$rnd = rand(0, 1000000);
$key = strtoupper(substr(md5( microtime() * $rnd),1,5));
$this->clave = $key;
$this->captcha = imagecreatefromgif('bg.gif');
$posicion_x=15;
for($i = 0;$i<strlen($key);$i++){
$r=rand(0,255);
$g=rand(0,255);
$b=rand(0,255);
$posicion_y=rand(20,40);
$colorText = imagecolorallocate($this->captcha, $r, $g, $b);
imagestring($this->captcha, 30, $posicion_x, $posicion_y, $key[$i], $colorText);
$posicion_x+=25;
}
//Fix con el color de la segunda letra
$white = ImageColorAllocate($this->captcha,0,0,0);
ImageColorTransparent($this->captcha,$white);
}
public function imprimir()
{
if (!empty($this->frames) AND !empty($this->framed))
{
$gif = new GIFEncoder($this->frames, $this->framed, 0, 2, 0, 0, 0, 'url');
Header ('Content-type:image/gif');
echo $gif->GetAnimation();
imagedestroy($this->captcha);
}else{
Header('Content-type:image/gif');
imagegif($this->captcha);
}
}
public function guardar()
{
$_SESSION['CAPTCHA_TEXT'] = $this->clave;
return $this->clave;
}
}
class Animacion extends Captcha
{
public $frames;
public $framed;
function __construct($aleatorio = 1)
{
parent::__construct();
if ($aleatorio == 1) {
$n = rand(1,3);
$n == 1 ? $this->circulo() : 'no' ;
$n == 2 ? $this->bum() : 'no' ;
$n == 3 ? $this->desliz() : 'no' ;
}
}
public function circulo()
{
$circulo_x = 40;
$circulo_y = 0;
$frames_x = 20;
for($b=0;$b<$frames_x;$b++){
$im = imagecreatetruecolor(150, 80);
imagecopy($im, $this->captcha, 0, 0, 0, 0, imagesx($this->captcha), imagesy($this->captcha));
//fix
$white = ImageColorAllocate($im,255,255,255);
ImageFill($im,0,0,$white);
$circulo = imagecolorallocate($im, 0, 0, 0);
imagefilledellipse( $im, $circulo_y, $circulo_x, 30, 30, $circulo );
$fname = 'tmp/'.$b.'.gif';
imagegif($im, $fname);
$this->frames[] = $fname;
$this->framed[] = 1;
$circulo_y+=10;
imagedestroy($im);
}
$this->imprimir();
}
public function bum()
{
$frames_x = 30;
for($b=0;$b<$frames_x;$b++){
$im = imagecreatetruecolor(150, 80);
imagecopy($im, $this->captcha, 0, 0, 0, 0, imagesx($this->captcha), imagesy($this->captcha));
//fix
$white = ImageColorAllocate($im,255,255,255);
ImageFill($im,0,0,$white);
imagefilledrectangle($im,($b*5),($b*5),10+($b*5),10+($b*5),0);
imagefilledrectangle($im,($b*1),($b*5),10+($b*1),10+($b*5),0);
imagefilledrectangle($im,($b*3)*2,($b*1)+$b,10+($b*3)*2,10+($b*1)+$b,0);
imagefilledrectangle($im,($b*4)*2,($b*2)+$b,10+($b*4)*2,10+($b*2)+$b,0);
$fname = 'tmp/'.$b.'.gif';
imagegif($im, $fname);
$this->frames[] = $fname;
$this->framed[] = 1;
imagedestroy($im);
}
$this->imprimir();
}
public function desliz()
{
$imgwidth = imagesx($this->captcha);
$imgheight = imagesy($this->captcha);
$frames_x = 30;
for($b=0;$b<$frames_x;$b++){
$im = imagecreatetruecolor(150, 80);
imagecopy($im, $this->captcha, 0, 0, 0, 0, imagesx($this->captcha), imagesy($this->captcha));
//fix
$white = ImageColorAllocate($im,255,255,255);
ImageFill($im,0,0,$white);
imagefilledrectangle($im,($b - 1) * 8 + 8,1,$imgwidth,$imgheight, 0);
$fname = 'tmp/'.$b.'.gif';
imagegif($im, $fname);
$this->frames[] = $fname;
$this->framed[] = 1;
imagedestroy($im);
}
$this->imprimir();
}
}
// Animacion aleatoria
$showtime = new Animacion();
//$showtime->guardar();
// Seleccionar animacion
//$showtime = new Animacion(0);
//$showtime->bum();
// Sin animacion
//$showtime = new Captcha();
//$showtime->imprimir();
?>