Foros del Web » Programando para Internet » PHP »

[APORTE] EasyThumbnail 2.0

Estas en el tema de [APORTE] EasyThumbnail 2.0 en el foro de PHP en Foros del Web. Hola, Cree la nueva version del EasyThumbnail. Agrege public y private a peticion del publico . Nuevas funciones: Capas de crear bordes a las imagenes ...
  #1 (permalink)  
Antiguo 08/11/2008, 14:00
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
[APORTE] EasyThumbnail 2.0

Hola,
Cree la nueva version del EasyThumbnail.
Agrege public y private a peticion del publico.
Nuevas funciones:
  • Capas de crear bordes a las imagenes
  • Editar imagenes GIF y PNG con trasparencia
  • Crear una imagen desde 0 con el formato elejido
  • Editar imagen desde posision X1 Y1 a la X2 Y2
  • Insertar lineas
  • Funcion que te dice los errores producidos
  • Insertar imagen (codigo HTML)
  • Modernización del código
Se lo usa distinto.
Codigo:
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     : 2.0 (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 
$error=array();
    private 
$calidad;
    private 
$srcw;
    private 
$srch;
    private 
$ext;
    private 
$et;
    private 
$x=array(0,0);
    private 
$y=array(0,0);
    public function 
__construct($e,$w 60,$h 60,$u "#FFFFFF"){
    
$this->et=$e;
        if(
$e=="edit"){
            
$str=$w;
            if(!
file_exists($str))
                
$this->error('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);
            
imageAlphaBlending($this->imagenfalse); 
            
imageSaveAlpha($this->imagentrue); 
                break;
        case 
"GIF":
            
$this->ext="GIF";
            
$this->imagenImageCreateFromGIF ($str);
                break;
        default:
            
$this->error("Extencion del archivo a editar no valida.");
                break;
        }
          
$this->srcw=@imagesx($this->imagen);
          
$this->srch=@imagesy($this->imagen);
        
$this->calidad=75;
        
$this->automatico(75);
    }elseif(
$e=="new"){
    
$this->width($w);
    
$this->height($h);
    
$this->image ImageCreateTrueColor($this->width,$this->height);
          list(
$c1,$c2,$c3)=$this->detecColor($u);
            
$c=@imagecolorallocate($this->image$c1,$c2,$c3);
             @
imagefill($this->image,0,0,$c);
        }
            }
    public function 
recortar($x1 0,$y1 0,$x2 0,$y2 0){
        
$this->x[1]=$x1;
        
$this->x[2]=$x2;
        
$this->y[1]=$y1;
        
$this->y[2]=$y2;
            }
    private function 
detecExt($str,$t false){
        if(!
$t){
            
$this->ext=ereg_replace(".*\.(.*)$","\\1",$str);
            
$this->ext=strtoupper($this->ext);
        }else{
            
$e=ereg_replace(".*\.(.*)$","\\1",$str);
            
$e=strtoupper($e);
                return 
$e;
        }
            }
    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)=$this->detecColor($u);
        if(
$this->et=="edit")
            
$c=@imagecolorallocate($this->imagen,$c1,$c2,$c3);
        elseif(
$this->et=="new")
            
$c=@imagecolorallocate($this->image,$c1,$c2,$c3);
        if(
$this->et=="edit"){
            if(
$f==NULL)
                @
imagestring($this->imagen,$f2,$x,$y,$t,$c);
                    else
                        @
imagettftext($this->imagen$f2$a$x$y$c$f$t);
        }elseif(
$this->et=="new"){
            if(
$f==NULL)
                @
imagestring($this->image,$f2,$x,$y,$t,$c);
                    else
                        @
imagettftext($this->image$f2$a$x$y$c$f$t);
                            }
                                }
    public function 
borde($px 1,$u){
    
$px=($px-1);
        for(
$i=0;$i<=$px;$i++){
            
$this->linea(0,$i$this->width,$i,$u);
            
$this->linea($i,$this->height,$i,0,$u);
            
$this->linea(0,($this->height-$i)-1,$this->width,($this->height-$i)-1,$u);
            
$this->linea(($this->width-$i)-1,0, ($this->width-$i)-1$this->height$u);
        }
            }
    public function 
linea($x1,$y1,$x2,$y2,$u "#000000"){
    list(
$c1,$c2,$c3)=$this->detecColor($u);
        if(
$this->et=="edit"){
            
$c=@imagecolorallocate($this->imagen,$c1,$c2,$c3);
            @
imageline($this->imagen,$x1,$y1,$x2,$y2,$c);
        }elseif(
$this->et=="new"){
            
$c=@imagecolorallocate($this->image,$c1,$c2,$c3);
            @
imageline($this->image,$x1,$y1,$x2,$y2,$c);
        }
            }
    private function 
detecColor($u){
    if(
strchr($u,"#"))
                return @
sscanf($u,'#%2x%2x%2x');
            else
                return @
sscanf($u,'%2x%2x%2x');
    }
    private function 
error($t){
        
$this->error[]="<li>".$t."</li>";
    }
    public function 
errores(){
        if(!empty(
$this->error))
            return 
"Errores detectados:<ul>".implode("\n",$this->error)."</ul>";
    }
    public function 
crear($dir$fun NULL)    {
    if(
$this->et=="edit"){
        if(
$dir=="")
            return 
false;
            if(
$this->width=="" && $this->height=="")
                
$this->error('No se a selecionado un tamaño.');
                
$this->image = @ImageCreateTrueColor($this->width,$this->height);
                if(
$this->ext=="GIF"){
                    
$color=imagecolortransparent($this->imagen);
                        if(
$color!=-1){
                            
$trnprt_color = @imagecolorsforindex($this->imagen$color);
                             
$trnprt_indx = @imagecolorallocatealpha($this->image$trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue'], $trnprt_color['alpha']);
                             @
imagefill($this->image00$trnprt_indx);
                              @
imagecolortransparent($this->image$trnprt_indx);
                                        }
                                            }
                   @
imagecopyresampled ($this->image$this->imagen$this->x[1], $this->y[1], $this->x[2], $this->y[2],$this->width ,$this->height ,$this->srcw $this->srch);
    switch(
$this->detecExt($dir,true)){
        case 
"JPG":
            
$creat=@imageJPEG($this->image,$dir,$this->calidad);
                break;
        case 
"JPEG":
            
$creat=@imageJPEG($this->image,$dir,$this->calidad);
                break;
        case 
"PNG":
            
$creat=@imagePNG($this->image,$dir);
                break;
        case 
"GIF":
            
$creat=@imageGIF($this->image,$dir);
                break;
        default:
            
$this->error("Extencion del archivo a crear no valida.");
                break;
                }
    }elseif(
$this->et=="new"){
    
$this->detecExt($dir);
    switch(
$this->ext){
        case 
"JPG":
            
$creat=@imageJPEG($this->image,$dir,$this->calidad);
                break;
        case 
"JPEG":
        
$creat=    @imageJPEG($this->image,$dir,$this->calidad);
            break;
        case 
"PNG":
            
$creat=@imagePNG($this->image,$dir);
                break;
        case 
"GIF":
            
$creat=@imageGIF($this->image,$dir);
                break;
        default:
            
$this->error("Extencion del archivo a crear no valida.");
                break;
            }
                }
    if(
$creat)
        @
imagedestroy($this->image);
     else
        
$this->error("No se pudo crear el archivo \"".$dir."\", porque no se a podido abrir el archivo base.");
        if(
$fun=="ver" && $creat)
        echo 
"<img src=\"".$dir."\" width=\"".$this->width."\" height=\"".$this->height."\" />";
                    }
                        }
?>
Modo de uso:
Para edita una imagen:
Código PHP:
$t= new EasyThumbnail("edit",'logo.jpg'); 
Para crear una imagen:
Código PHP:
$t= new EasyThumbnail("new",width,height,color de fondo HTML); 
Para escribir, dar tamaño y calidad es igual.

Despues para ver los errores que se produsieron:
Código PHP:
echo $t->errores(); 
Crear borde:
Código PHP:
$t->borde(GROSOR,COLOR HTML); 
Para recortar (solo al editar):
Código PHP:
$t->recortar(X1,Y1,X2,Y2); 
Para crear una linea:
Código PHP:
$t->linea(X1,Y2,X2,Y2,COLOR HTML); 
y para crear:
Código PHP:
$t->crear(NOMBRE DE LA IMAGEN A CREAR); 
y para crear y verla:
Código PHP:
$t->crear(NOMBRE DE LA IMAGEN A CREAR,"ver"); 
Gracias
Salu2
__________________
Half Music - www.halfmusic.com

Última edición por pato12; 25/11/2008 a las 16:41 Razón: Saque el archivo BMP
  #2 (permalink)  
Antiguo 25/11/2008, 15:04
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail 2.0

la nueva version!!! voy a probarla

joder no la entiendo casi :S

puedes poner las nuevas funciones que has insertado ?

Última edición por nfo; 25/11/2008 a las 15:10
  #3 (permalink)  
Antiguo 25/11/2008, 15:31
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail 2.0

PAto12 pero el error del bmp microsoft sige, yo creo que la funcion que reduce la imagen bmp en php no funciona bien.... no lo entiendo...
  #4 (permalink)  
Antiguo 25/11/2008, 16:40
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] EasyThumbnail 2.0

Tienes razón, es un error (bugs) de PHP.
Voy a sacar el archivo bmp, hasta que lo solucione.
Gracias
Salu2
__________________
Half Music - www.halfmusic.com
  #5 (permalink)  
Antiguo 25/11/2008, 18:21
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: [APORTE] EasyThumbnail 2.0

personalmente, yo no daría soporte para imágenes no concebidas para la Web... solo para jpg, png y gif

demás, no tiene nada de malo indentar un poco mejor el código... se ve, como que, muy amontonado...

por ultimo, pienso que son innecesarios los @ ... de verdad, si funciona bien tu clase... no necesitas suprimir los errores

suerte!
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #6 (permalink)  
Antiguo 25/11/2008, 21:29
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] EasyThumbnail 2.0

Hola,
Suprimo los error es por que la funcion $t->errores(); te los tienes que decir.
Y bueno, el formato BMP no lo voy a incluir.
Gracias
Salu2
__________________
Half Music - www.halfmusic.com
  #7 (permalink)  
Antiguo 26/11/2008, 13:39
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail 2.0

Cita:
Iniciado por pato12 Ver Mensaje
Hola,
Suprimo los error es por que la funcion $t->errores(); te los tienes que decir.
Y bueno, el formato BMP no lo voy a incluir.
Gracias
Salu2
Entonces pato12 como podria prevenir que solo subieran imagenes en formato jpg, gif, png y todas las demás no?.

a mi me sube todo tipo de imagenes.

Última edición por nfo; 27/11/2008 a las 03:45
  #8 (permalink)  
Antiguo 26/11/2008, 18:39
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: [APORTE] EasyThumbnail 2.0

espero no salirme del tema... y ojala solo se hable del aporte aquí mismo

nfo, ese tema ya esta tratado... no hay necesidad de preguntarle directamente a pato12, ya que su aporte es de manipulación de imágenes.... y no de uploads....

bien, no tiene relación tu pregunta... al menos no aquí, bien puedes investigar un poco en el foro... y resolverlo fácilmente

espero no molestar mas, suerte!
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #9 (permalink)  
Antiguo 27/11/2008, 03:46
nfo
 
Fecha de Ingreso: octubre-2008
Ubicación: EsPaCiO TiEmPo
Mensajes: 408
Antigüedad: 15 años, 6 meses
Puntos: 5
Respuesta: [APORTE] EasyThumbnail 2.0

Cita:
Iniciado por pateketrueke Ver Mensaje
espero no salirme del tema... y ojala solo se hable del aporte aquí mismo

nfo, ese tema ya esta tratado... no hay necesidad de preguntarle directamente a pato12, ya que su aporte es de manipulación de imágenes.... y no de uploads....

bien, no tiene relación tu pregunta... al menos no aquí, bien puedes investigar un poco en el foro... y resolverlo fácilmente

espero no molestar mas, suerte!
nada hombre no me di cuenta pero en la nueva version si te das cuentas sube las imagenes al directorio por eso le preguntaba.

Quitando la subida de imagen bmp todo lo dem´s esta estupendamente.

Saludos PAto12.
  #10 (permalink)  
Antiguo 27/11/2008, 08:45
 
Fecha de Ingreso: septiembre-2008
Mensajes: 28
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: [APORTE] EasyThumbnail 2.0

buenas!!!

no se si debo preguntarlo aki, pero me parece innecesario abrir un post nuevo, pero como veo que Pato12 controla mucho el tema... XDXD

queria preguntaros lo siguiente:

yo tengo una tabla donde almaceno las direcciones tanto de la imagen original, como la de la miniatura.
se hacer que me muestre todas las imagenes pero una debajo de otra o al lado, lo unico que no se como colocar el codigo php dentro de la tabla html para que por ejemplo cada 4 imagenes en horizontal salte de linea y me muestre otras cuatro, asi hasta que se acabe.

se que es una tonteria pero estoy rebanandome la sesera para conseguirlo con los contadores pero no me sale.

me podeis hechar una mano??? porfavor!! y que dios os lo pague con muchos ñaca ñaca y pocos niños XDXDXD
  #11 (permalink)  
Antiguo 27/11/2008, 09:49
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: [APORTE] EasyThumbnail 2.0

sharkie, hay un aporte para esto... por favor, acude a el

http://www.forosdelweb.com/f18/aport...tablas-618528/
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #12 (permalink)  
Antiguo 27/11/2008, 10:19
 
Fecha de Ingreso: septiembre-2008
Mensajes: 28
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: [APORTE] EasyThumbnail 2.0

mil millones de gracias, que no lo habia visto!
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




La zona horaria es GMT -6. Ahora son las 07:15.