Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/10/2008, 18:57
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
[APORTE] EasyThumbnail

Hola,
Hice otra clase que sirve para redimensionar una imagen, para crear Thumbnail y para escribir una imagen fácilmente.
El código es:
EasyThumbnail.php
Código PHP:
<?php
/*******************************************************************************
** *****************************************************************************
**                               EasyThumbnail                                **
** *****************************************************************************
** Nombre      : EasyThumbnail                                                **
**                                                                            **
** Creador     : Pato12 <de Forosdelweb.com>                                  **
**                                                                            **
** Description : Sirve para redimensionar una imagen, para crear Thumbnail    **
**               y para escribir una imagen fácilmente.                       **
**                                                                            **
** Contacto    : MP de forosdelweb.com al usuario Pato12                      **
**                                                                            **
** Version     : 1.5 (BETA)                                                   **
**                                                                            **
** Web del                                                                    **
** creador     : www.halfmusic.com.ar                                         **
********************************************************************************
********************************************************************************
*   Este scriopt PHP es libre de usar siempre cuando no borren estas lineas
*   y respeten la licencia GPL :
*   http://opensource.org/licenses/gpl-license.php GNU Public License
**********************************************************************************/
    
class EasyThumbnail{
    var 
$imagen;
    var 
$image;
    var 
$height;
    var 
$width;
    var 
$calidad;
    var 
$srcw;
    var 
$srch;
    var 
$ext;
    var 
$txt;
    function 
EasyThumbnail($str){
    if(!
file_exists($str))
    die(
'¡El archivo '.$str.' no existe!');
    
$this->detecExt($str);
    switch(
$this->ext){
    case 
"JPG":
    
$this->ext="JPEG";
    
$this->imagen ImageCreateFromJPEG ($str);
    break;
    case 
"JPEG":
    
$this->ext="JPEG";
    
$this->imagen ImageCreateFromJPEG ($str);
    break;
    case 
"PNG":
    
$this->ext="PNG";
    
$this->imagen ImageCreateFromPNG ($str);
    break;
    case 
"GIF":
    
$this->ext="GIF";
    
$this->imagenImageCreateFromGIF ($str);
    break;
    case 
"WBMP":
    
$this->ext="WBMP";
    
$this->imagenImageCreateFromWBMP ($str);
    break;
    default:
    die(
"Error - extencion no valida");
    break;
    }
      
$this->srcw=imagesx($this->imagen);
      
$this->srch=imagesy($this->imagen);
    
$this->calidad=75;
    
$this->height 50;
    
$this->width 50;
    }
    function 
detecExt($str){
    
$this->ext=ereg_replace(".*\.(.*)$","\\1",$str);
    
$this->ext=strtoupper($this->ext);
    }
    function 
height($str=50){
    if(
$str<50)
    
$str=floor($this->srch*$this->width/$this->srcw);
        
$this->height $str;
    }
    function 
width($str=50)    {
    if(
$str<50)
    
$str=floor($this->srcw*$this->height/$this->srch);
        
$this->width $str;
    }
    function 
calidad($str=75){
        
$this->calidad=$str;
    }
    function 
automatico($str=50)    {
    if (
$this->srcw<$this->srch) {
    
$this->height=$str;
    
$this->width=floor($this->srcw*$this->height/$this->srch);
    }else{
    
$this->width=$str;
    
$this->height=floor($this->srch*$this->width/$this->srcw);
    }
      if (
$this->width>$this->srcw && $this->height>$this->srch) {
    
$this->width=$this->srcw;
    
$this->height=$this->srch;
    }
    }
    function 
text($t,$x=0,$y=0,$u="#000000",$f=NULL,$f2=20,$a=0){
    list(
$c1,$c2,$c3)=sscanf($u'#%2x%2x%2x');
    
$c=imagecolorallocate($this->imagen,$c1,$c2,$c3);
    if(
$f==NULL)
    @
imagestring($this->imagen,$f2,$x,$y,$t,$c);
    else
    @
imagettftext($this->imagen$f2$a$x$y$c$f$t);
    }
    function 
crear($dir)    {
    if(
$dir=="")
    return 
false;
    if(
$this->width=="" && $this->height=="")
    die(
'¡Selecione tamaño!');
    
$this->image ImageCreateTrueColor($this->width,$this->height);
    @
imagecopyresampled ($this->image$this->imagen0000,$this->width ,$this->height ,$this->srcw $this->srch);
    switch(
$this->ext){
    case 
"JPG":
    
imageJPEG($this->image,$dir,$this->calidad);
    break;
    case 
"JPEG":
    
imageJPEG($this->image,$dir,$this->calidad);
    break;
    case 
"PNG":
    
imagePNG($this->image,$dir);
    break;
    case 
"GIF":
    
imageGIF($this->image,$dir);
    break;
    case 
"WBMP":
    
imageWBMP($this->image,$dir);
    break;
    default:
    die(
"Error - extencion no valida");
    break;
    }
    @
imagedestroy($this->image);
    }
    }
?>
Modo de uso:
Código PHP:
include('EasyThumbnail.php');
$t= new EasyThumbnail("logo.jpg");
$t->width(300);
$t->height(150);
$t->calidad(100);
$t->text('Bienvenido usuario',10,50,"#000000",'arial.ttf',20,0);
$t->text('Bienvenido usuario',9,49,"#FFFFFF",'arial.ttf',20,0);
$t->crear("logo_user.jpg"); 
Podes escribir todas las veses que quieras.
Explicasion:
Incluimos la clase y la ejecutamos.
Código PHP:
include('EasyThumbnail.php');
$t= new EasyThumbnail("logo.jpg"); 

Le damos el tamaño:
Código PHP:
$t->width(300);
$t->height(150); 
o
Código PHP:
$t->automatico(300); 
Calidad de la imagen jpg.
Código PHP:
$t->calidad(100); 

Incluimos texto.
Código PHP:
$t->text('Bienvenido usuario',10,50,"#000000",'arial.ttf',20,0);
$t->text('Bienvenido usuario',9,49,"#FFFFFF",'arial.ttf',20,0); 
es decir:
$t->text( MI TEXTO , X , Y , COLOR HTML , ARCHIVO .TTF , TAMANIO , ROTACION );
o si no tienen archivo .ttf:
Código PHP:
$t->text('Bienvenido usuario',10,50,"#000000",NULL,5);// ADV.: SE VE CHIQUITA LAS LETRAS, POR ESO RECOMENTAMOS EL OTRO METODO. 
Creamos la imagen, con el nombre y extencion que queremos.
Código PHP:
$t->crear('logo_user.jpg'); 
Lo mejor de todo, es que tecta la extencion.
Compatible con:
  • GIF
  • JPG
  • JPEG
  • PNG
  • WBMP
Es simple, es EasyThumbnail.

Gracias
Salu2
__________________
Half Music - www.halfmusic.com