Foros del Web » Programando para Internet » PHP »

APORTE: Crea una imagen facilmente

Estas en el tema de APORTE: Crea una imagen facilmente en el foro de PHP en Foros del Web. Hola, Ise un class para facilitar la creacion de imagenes con texto escrito. Ejemplo: Cita: Quiero crear un cartel de bienvenida para el usuario y ...
  #1 (permalink)  
Antiguo 05/06/2008, 17:55
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
APORTE: Crea una imagen facilmente

Hola,
Ise un class para facilitar la creacion de imagenes con texto escrito.
Ejemplo:
Cita:
Quiero crear un cartel de bienvenida para el usuario y otro para el usuario registrado.
Cita:
Crear una imagen para cada categoria de mi web, automaticamente.

Es totalmente editable a su medida y facil.
Consiste en:
Cita:
Un solo archivo
  • EasyImages.class.php
Este es el class:
EasyImages.class.php
Código PHP:
////////////////////////////
//  Class By Pato12      //
//  De Forosdelweb.com  //
//  Titulo: EasyImages //
//  Version: 1.0      //
///////////////////////
class EasyImages 
{
var 
$texto;
var 
$width;
var 
$height;
var 
$rojo_f;
var 
$verde_f;
var 
$azul_f;
var 
$rojo_t;
var 
$verde_t;
var 
$azul_t;
var 
$name;
var 
$font;
function 
text($t,$v){
if(
$v){
$this->texto=$t;
}
return 
$this->texto;
}
//
function name($t,$v){
if(
$v){
$this->name=$t;
}
return 
$this->name;
}
//
function width($t,$v){
if(
$v){
$this->width=$t;
}
return 
$this->width;
}
//
function height($t,$v){
if(
$v){
$this->height=$t;
}
return 
$this->height;
}
//
function rojo_f($t,$v){
if(
$v){
$this->rojo_f=$t;
}
return 
$this->rojo_f;
}
//
function verde_f($t,$v){
if(
$v){
$this->verde_f=$t;
}
return 
$this->verde_f;
}
//
function azul_f($t,$v){
if(
$v){
$this->azul_f=$t;
}
return 
$this->azul_f;
}
//
function rojo_t($t,$v){
if(
$v){
$this->rojo_t=$t;
}
return 
$this->rojo_t;
}
//
function verde_t($t,$v){
if(
$v){
$this->verde_t=$t;
}
return 
$this->verde_t;
}
//
function azul_t($t,$v){
if(
$v){
$this->azul_t=$t;
}
return 
$this->azul_t;
}
//
function font($t,$v){
if(
$v){
$this->font=$t;
}
return 
$this->font;
}
function 
crear_image(){
$texto=$this->texto;
$name=$this->name;
$width=$this->width;
$height=$this->height;
$r_f=$this->rojo_f;
$g_f=$this->verde_f;
$b_f=$this->azul_f;
$r_t=$this->rojo_t;
$g_t=$this->verde_t;
$b_t=$this->azul_t;
$fuente=$this->font;
$im = @imagecreatetruecolor($width,$height); 
$colorf  = @imagecolorallocate($im$r_f,$g_f,$b_f); 
$colort  = @imagecolorallocate($im$r_t,$g_t,$b_t); 
@
imagefilledrectangle($im00$width$height,$colorf); 
@
imagettftext($im,2001020$colort$fuente$texto); 
@
imagejpeg($im,$name.".jpg"); 
@
imagedestroy($im); 
}
function 
escribir(){
echo 
"<img src='".$this->name.".jpg' width='".$this->width."' height='".$this->height."'/>";
}

y el codigo para crear la imagen es el siguiente:
Código PHP:
include('EasyImages.class.php');
$crear=new EasyImages();
$crear->text("Bienevinos a mi web",true);// Texto
$crear->width(400,true);// Ancho
$crear->height(30,true);// Alto
$crear->rojo_f(255,true); // Porsentaje de color rojo en el fondo
$crear->verde_f(255,true);// Porsentaje de color verde en el fondo
$crear->azul_f(255,true);// Porsentaje de color azul en el fondo
$crear->rojo_t(0,true);// Porsentaje de color rojo en el letras
$crear->verde_t(0,true);// Porsentaje de color verde en el letras
$crear->azul_t(0,true);// Porsentaje de color azul en el letras
$crear->name("alg1o",true);// Nombre de la imagen
$crear->font("arial.ttf",true); // Ubicasion de la fuente
$crear->crear_image(); // Creamos la imagen
$crear->escribir(); // Lo escrbimos 
[ Funciona de 10 el codigo ]
Pueden sacar los fonts (.ttf) desde las siguientes direciones:
http://www.tiposdeletra.com/
http://www.creamundo.com/index.php?lang=es
http://www.fontreactor.com/
Espero que les guste el codigo.
Espero sus cometarios
Gracias
Salu2
__________________
Half Music - www.halfmusic.com
  #2 (permalink)  
Antiguo 05/06/2008, 18:17
Avatar de jaronu  
Fecha de Ingreso: febrero-2008
Mensajes: 2.183
Antigüedad: 16 años, 1 mes
Puntos: 52
Respuesta: APORTE: Crea una imagen facilmente

Hola pato12

me parece interesante tu clase, pero la acabo de probar en local y no me hace nada.
no se sie sque hoy estoy muy cansado, pero me sale la pantalla en blanco
  #3 (permalink)  
Antiguo 05/06/2008, 18:25
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
Respuesta: APORTE: Crea una imagen facilmente

Hola jaronu,
Recuerda que en esta linea:
$crear->font("arial.ttf",true); // Ubicasion de la fuente
deves poner una direcion de una fuente (.ttf)
y di link de descarga de fuentes.
Gracias por tu comentario.
Salu2
__________________
Half Music - www.halfmusic.com
  #4 (permalink)  
Antiguo 05/06/2008, 18:37
Avatar de jaronu  
Fecha de Ingreso: febrero-2008
Mensajes: 2.183
Antigüedad: 16 años, 1 mes
Puntos: 52
Respuesta: APORTE: Crea una imagen facilmente

ahora si

Muy bueno el aporte, no paras pato12, eso es bueno.

Un saludo
  #5 (permalink)  
Antiguo 05/06/2008, 18:53
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
Respuesta: APORTE: Crea una imagen facilmente

Muchas gracias jaronu.
__________________
Half Music - www.halfmusic.com
  #6 (permalink)  
Antiguo 05/06/2008, 23:35
Avatar de chalchis  
Fecha de Ingreso: julio-2003
Mensajes: 1.773
Antigüedad: 20 años, 9 meses
Puntos: 21
De acuerdo Respuesta: APORTE: Crea una imagen facilmente

muy bueno el aporte se agradece

saludos
__________________
gerardo
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 09:35.