Foros del Web » Programando para Internet » PHP »

[APORTE] EasyThumbnail

Estas en el tema de [APORTE] EasyThumbnail en el foro de PHP en Foros del Web. 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: ...
  #1 (permalink)  
Antiguo 27/10/2008, 18:57
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 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
  #2 (permalink)  
Antiguo 31/10/2008, 04:01
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail

estupendo!!! andaba buscando una cosa asi muy buen aporte.

TE voy a dar un punto de karma gracias !
  #3 (permalink)  
Antiguo 31/10/2008, 14:13
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Respuesta: [APORTE] EasyThumbnail

muy interesante lastima que esta para php4, deberías empezar a migrar a php5. saludos
  #4 (permalink)  
Antiguo 01/11/2008, 06:09
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail

Cita:
Iniciado por destor77 Ver Mensaje
muy interesante lastima que esta para php4, deberías empezar a migrar a php5. saludos
funciona en php 5. de echo yo estoy programando en php 5,
  #5 (permalink)  
Antiguo 01/11/2008, 11:28
okram
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: [APORTE] EasyThumbnail

Si colocas el máximo nivel de reporte de errores, ese script lanza muchos, pues la forma cómo PHP 5 implementó la POO es toalmente diferente a PHP 4 (Un ejemplo rápido, es el abandono del keyword var delante de las propiedades del método, debiendo usarse public, private, etc.

A partir de PHP 6, las clases programadas para PHP 4 se supone que serán compatibles (no errores).

Pero es cierto eso, pato12, debería cuidar ese aspecto, pues un error allí arruinaría el script. Por lo tanto, debes tomar en cuenta el más mínimo detalle.

Saludos,
  #6 (permalink)  
Antiguo 01/11/2008, 13:51
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail

ostras es verdad no me habia fijado en eso!!! joe que despiste, pero si cambias el var por private ya estara todo echo..
  #7 (permalink)  
Antiguo 03/11/2008, 09:03
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Respuesta: [APORTE] EasyThumbnail

nfo, a lo que decia okram me referia yo, usar private en las variables y public en las funciones para mayoer seguridad y demas cosas de POO.

salu2
  #8 (permalink)  
Antiguo 03/11/2008, 11:48
okram
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: [APORTE] EasyThumbnail

Cita:
Iniciado por destor77 Ver Mensaje
private en las variables y public en las funciones para mayoer seguridad y demas cosas de POO.
No necesariamente. Hay métodos (funciones) que deben ser declarados como privados, y el poner public a las propiedades (variables) puede tener también su utilidad. Además, esos no son los dos uúnicos modificadores que existen en la POO.

Saludos,
  #9 (permalink)  
Antiguo 25/11/2008, 14:56
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail

Pato12 respuesta a tu mensaje.

Pues n ose compañero cual puede ser el fallo, yo me tome la libertad de cambiar un poco tu clase y la puse asi. pero el fallo persiste y es solo con el bmp con png o gif todo perfecto.

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{
    private 
$imagen;
    private 
$image;
    private 
$height;
    private 
$width;
    private 
$calidad;
    private 
$srcw;
    private 
$srch;
    private 
$ext;
    private 
$txt;
    public 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 
"BMP":
    
$this->ext="BMP";
    
$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;
    }
    public function 
detecExt($str){
    
$this->ext=ereg_replace(".*\.(.*)$","\\1",$str);
    
$this->ext=strtoupper($this->ext);
    }
    public function 
height($str=50){
    if(
$str<50)
    
$str=floor($this->srch*$this->width/$this->srcw);
        
$this->height $str;
    }
    public function 
width($str=50){
    if(
$str<50)
    
$str=floor($this->srcw*$this->height/$this->srch);
        
$this->width $str;
    }
    public function 
calidad($str=75){
        
$this->calidad=$str;
    }
    public 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;
    }
    }
    public 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);
    }
    public 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 
"BMP":
    
imageWBMP($this->image,$dir);
    break;
    default:
    die(
"Error - extencion no valida");
    break;
    }
    @
imagedestroy($this->image);
    }
    }
?>
Espero que no te haya importando.
  #10 (permalink)  
Antiguo 25/11/2008, 15:00
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Respuesta: [APORTE] EasyThumbnail

Hola,
No se cual puede ser el fallo. Ya voy a tratar de repararlo.
Pero esta es la version vieja. Te paso el link de la 2.0:
http://www.forosdelweb.com/f18/aport...-2-0-a-642414/
Gracias
Salu2
__________________
Half Music - www.halfmusic.com
  #11 (permalink)  
Antiguo 25/11/2008, 15:02
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail

Espero que no haya muchos cambios gracias pato12
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 3 personas




La zona horaria es GMT -6. Ahora son las 01:29.