palabras.php (imagen)
Código PHP:
<?php
/*
===========================================================*
My-Img by mandm.
URL : http://www.mandm.org.mx
LINK PERMANENTE DEL SCRIPT : http://www.mandm.org.mx/archivo/8/my_words.mandm?
FUENTES BITMAP PROVEHIDAS POR : http://www.widgnet.com
===========================================================*
*/
#;
#; CONFIGURACIÓN :
#;
#; Para crear una imágen llame a la función: create_img();
#; Para validar un texto enviado por el usuario use: valid_cookie();
#; Logitud máxima de caracteres
$maxLength = 6;
#; Imágen de fondo, el tamaño de la imágen creada
#; será el mismo que el de éste archivo.
$base_img = "base.gif";
#; Enviar cookie para validar el texto de la imágen.
#; El contenido de la cookie se decodificará mediante base64
#; Para decodificar el contenido haga :
#; base64_decode($_COOKIE[NOMBRE_DE_LA_COOKIE]);
#; O use la función 'valid_cookie($_COOKIE[NOMBRE_DE_LA_COOKIE])' que viene en este script
#; Esta función devuelve un valor Booleano
#; ( true ) si es correcto, ( false ) en caso contrario.
$sendCookie = true;
#; Nombre de la cookie ( solo si $sendCookie = true )
$nameCookie = "codigoseguridad";
#; Alineación horizontal (left[izquierda],right[derecha],center[centro])
#; O seleccione su ubicación exacta horizontal en número
$align = "center";
#; Alineación vertical (middle[centro],top[arriba],bottom[abajo])
#; O seleccione su ubicación exacta vertical en número
$valign = "middle";
#; Cargar fuente desde archivo ( opcional ) [ .. la fuente debe ser compatible con bitmap ]
$trueType = true;
#; (solo sí $trueType=true) nombre del archivo de imágen
$srcFont = "fuentes/fuente_4.gdf";
#; Tamaño de la fuente
$fontSize = 12;
#; true si el texto debe cargarse del archivo 'palabras.txt' aletoriamente,
#; false para una cadena de caracteres aletoria.
$isWord = false;
#; Colores RGB $colorFont = array(255,255,255);
#; O $colorFont = 'rand'; si desea que cada vez la cadena sea de distinto color.
$colorFont = 'rand';
#; FIN CONFIGURACIÓN
#; Función para validar la cookie -
function valid_cookie($texto){
global $HTTP_COOKIE_VARS;
$cookie = base64_decode($HTTP_COOKIE_VARS[$GLOBALS["codigoseguridad"]]);
if(trim($cookie)==trim($texto)){
return true;
}
return false;
}
#; Verificando los datos de configuración
function check_info(){
if($GLOBALS['isWord'] == true)
{
if(file_exists("palabras.txt"))
{
$nameFile = "palabras.txt";
$file = file($nameFile);
$numL = count($file);
if($numL > 1){
$textImg = $file[rand(0,$numL)];
} else {
$textImg = create_rand();
}
} else {
$textImg = create_rand();
}
} else {
$textImg = create_rand();
}
$return = array();
$return['texto'] = $textImg;
if($GLOBALS['sendCookie'] == true)
{
$return['base_texto'] = base64_encode($return['texto']);
}
if($GLOBALS['trueType'] == true)
{
if(!file_exists($GLOBALS['srcFont'])){
exit("¡ Error ! .... el archivo {$GLOBALS[srcFont]} no existe.");
} else {
if(! (@imageloadfont($GLOBALS['srcFont'])) ){
exit("¡ Error ! .... el archivo {$GLOBALS[srcFont]} no tiene una extención adecuada.");
} else {
$return['font'] = $GLOBALS['srcFont'];
$return['size'] = $GLOBALS['fontSize'];
}
}
} else {
$return['size'] = 5;
}
if(is_array($GLOBALS['colorFont']))
{
if(sizeof($GLOBALS['colorFont']) < 3){
$return['fcolor'] = array(0,0,0);
} else {
$return['fcolor'] = array(
$GLOBALS['colorFont'][0],
$GLOBALS['colorFont'][1],
$GLOBALS['colorFont'][2]
);
}
} elseif(strtolower(trim($GLOBALS['colorFont'])) == 'rand'){
$maxX = 0;
$maxX = 255;
$return['fcolor'] = array(
rand($maxX,$maxC),
rand($maxX,$maxC),
rand($maxX,$maxC)
);
} else {
$return['fcolor'] = array(0,0,0);
}
$return['w'] = $GLOBALS['ImgWidth'];
$return['h'] = $GLOBALS['ImgHeight'];
return $return;
}
#; Random de letras
function create_rand(){
global $maxLength;
$uid = md5( uniqid( rand(0,time()) ) );
if(strlen($uid) > $maxLength){
$uid = substr($uid,0,$maxLength);
}
return $uid;
}
#; Crear la imágen
function create_img(){
global $base_img,$align,$valign;
$i = check_info();
$extencion = strtolower(array_pop(explode('.',$base_img)));
$arriba = strtolower($valign);
$alinear = strtolower($align);
$tamanio = getimagesize($base_img);
if($extencion == 'gif'){
$im = imagecreatefromgif($base_img);
} else
if($extencion == 'png'){
$im = imagecreatefrompng($base_img);
} else
if($extencion == 'jpg'){
$im = imagecreatefromjpeg($base_img);
} else
if($extencion == 'bmp'){
$im = imagecreatefromwbmp($base_img);
} else {
die('Extencion de imágen no válida');
}
if(isset($i['font'])){
$font = imageloadfont($i['font']);
$fontw = imagefontwidth($font);
$fonth = imagefontheight($font);
} else {
$font = $i['size'];
$fontw = imagefontwidth($i['size']);
$fonth = imagefontheight($i['size']);
}
if($arriba == 'top'){
$ty = 0;
} else
if($arriba == 'bottom'){
$ty = ( imagesy($im) - ($fonth+1) );
} else
if($arriba == 'middle'){
$ty = ( imagesy( $im ) / 2 ) - ( $fonth/2 );
} else
if(is_numeric($arriba)){
$ty = $arriba;
} else {
$ty = $fonth;
}
if(strlen($i['texto']) > $GLOBALS['maxLength']){
$i['texto'] = substr($i['texto'],0,$GLOBALS['maxLength']);
}
if($alinear == 'left'){
$tx = 0;
} else
if($alinear == 'center'){
$tx = ( imagesx($im) / 2 ) - ( ($fontw*strlen(trim($i['texto'])))/2 );
} else
if($alinear == 'right'){
$tx = imagesx($im) - ($fontw*(strlen(trim($i['texto']))));
} else
if(is_numeric($alinear)){
$ty = $alinear;
} else {
$ty = $fontw;
}
$new_im = imagecreatetruecolor($tamanio[0],
$tamanio[1]
);
imagecopyresampled($new_im,
$im,
0,0,0,0,
$tamanio[0],
$tamanio[1],
imagesx($im),
imagesy($im)
);
$font_color = imagecolorallocate($new_im,$i['fcolor'][0],$i['fcolor'][1],$i['fcolor'][2]);
imagestring($new_im,$font,$tx,$ty,$i['texto'],$font_color);
if($GLOBALS['sendCookie']==true){
setcookie($GLOBALS['nameCookie'],base64_encode($i['texto']));
}
if($extencion == 'gif'){
header('Content-type: image/gif');
imagegif($new_im);
} else
if($extencion == 'png'){
header('Content-type: image/png');
imagepng($new_im);
} else
if($extencion == 'jpg'){
header('Content-type: image/jpeg');
imagejpeg($new_im,"",100);
} else
if($extencion == 'bmp'){
header('Content-type: image/wbmp');
imagewbmp($new_im,"");
}
imagedestroy($im);
imagedestroy($new_im);
return true;
}
#;Crear la imágen->
create_img();
#; Validar cookie->
#; if(valid_cookie($texto_enviado_por_el_usuario)){
#; echo "Escribiste correctamente el texto de la imágen";
#; } else {
#; echo "NO escribiste el texto de la imágen.";
#; }
?>
El de palabras.php me lo bajé de alguna web.
Salu2 y muchas gracias