Ver Mensaje Individual
  #8 (permalink)  
Antiguo 01/12/2008, 10:47
jmarquezrave
(Desactivado)
 
Fecha de Ingreso: febrero-2008
Mensajes: 83
Antigüedad: 16 años, 2 meses
Puntos: 0
Respuesta: como instalar...

Cita:
<?

class imag
{
var $font; // the font we wish to use
var $text; // the random text used in the image

function imag()
{
// set the font to use
$this->setFont('adler.ttf');
// seed the random number generater
srand((double)microtime()*1000000^getmypid());
}

/*
* mixed setFont(string $font)
* set the font file to use
*
* returns the old font name (if set) on sucess, false on failure (can not find file)
*/
function setFont($font)
{
// need to check if is a valid ttf file

// check that the file exists
if(file_exists($font))
{
$old_font=$this->font;
$this->font=$font;
if(!empty($old_font))
return $old_font;
return true;
}
else
return false;
}

/*
* string getFont()
*
* return the current set font
*/
function getFont()
{
return $this->font;
}

/*
* string createImage(int $width, int $height)
* create the image and output it's contents to the browser
*
* will return the random string used on the image
*/
function createImage($width=50,$height=20)
{
// send header for our image
header("Content-type:image/png");

// create an image
$im=imagecreate($width,$height);

// white background
$white=imagecolorallocate($im,255,255,255);

// black text and grid
$black=imagecolorallocate($im,249,94,0);

// get a random number to start drawing out grid from
$num=rand(0,5);

// generate a random string
$string=substr(strtolower(md5(uniqid(rand(),1))),0 ,4);

// in this font, the number 1 looks too much like I
if($this->getFont()=='adler.ttf')
$string=str_replace('1','a',$string);

// place this string into the image
imagettftext($im,11,0,9,19,$black,$this->getFont(),$string);

// create the image and send to browser
imagepng($im);
// destroy the image
imagedestroy($im);

// return the random text generated
return $this->text=$string;
}
}
?>
utilizo dos archivos este es el primero
y el segundo es:
Cita:
<?php
session_start();
require_once('imag.inc.php');
$im=&new imag;

/*
* want to use a different font ?? uncomment the line below and make sure it's the exact path.
* will return false on failure (couldn't find image)
*/
// $im->setFont('arial.ttf');

/*
*returns the random string placed on the image, this needs to then be placed into a session for comparison when the form is submitted
*
* if you change the font, you may also need to width & height of the image, you can do this by supplying the two arguements to createImage() - createImage(500,50);
*/
$_SESSION['text']=$im->createImage();
?>
a todo esto ajunto una fuente adler.tif.

En el servidor remoto (proveedor de host me funciona muy bien) pero no en el local host (appserver) hay que comentar que esta versiona del appserver tiene php6