Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/09/2011, 22:22
Avatar de CCB
CCB
 
Fecha de Ingreso: noviembre-2009
Ubicación: Perú
Mensajes: 65
Antigüedad: 15 años, 1 mes
Puntos: 3
Respuesta: Redimencionar imagen queda Distorcionada

Este codigo lo saque de una clase que hize para subir fotos y redimencionarla.

Esta parte es la que se encarga de hacer el thumb en 150px por lado.

Me avisas si no puedes hacerlo, te paso la class completa, no me deja postearla porque supera el numero permitido de caracteres.


Código PHP:
function Thumb(){
        
        if (
$this->listo_thumb == true){
                    
            
$this->imagen_thumb imagecreatefromjpeg($this->carpeta $this->newname);
            
            
$this->img_thumb imagecreatetruecolor(150150);
            

            
$this->new_ancho2 imagesx($this->imagen_thumb); 
            
$this->new_alto2 imagesy($this->imagen_thumb);
            
            
            
$this->ancho_thumb_max 150;
            
$this->alto_thumb_max 150;

            if(
$this->ancho_thumb_max/$this->new_ancho2 $this->alto_thumb_max/$this->new_alto2)
            {
                
$this->ancho_thumb $this->ancho_thumb_max;
                
$this->alto_thumb = ($this->new_alto2 $this->ancho_thumb) / $this->new_ancho2;
                
$this->image_x 0;
                
$this->image_y = ($this->alto_thumb_max $this->alto_thumb) / 2;
            }
            else
            {
                
$this->alto_thumb $this->alto_thumb_max;
                
$this->ancho_thumb = ($this->new_ancho2 $this->alto_thumb) / $this->new_alto2;
                
$this->image_y 0;
                
$this->image_x = ($this->ancho_thumb_max $this->ancho_thumb) / 2;
            }

                
            
imagecopyresampled($this->img_thumb$this->imagen_thumb$this->image_x$this->image_y00$this->ancho_thumb$this->alto_thumb$this->new_ancho2$this->new_alto2);
          
            
            
$this->copy_thumb imagejpeg($this->img_thumb,$this->carpeta "thumb/" $this->newname80);
   
            if (
$this->copy_thumb){
                
imagedestroy($this->img_thumb);
                
imagedestroy($this->imagen_thumb);
                
$this->message "Copiado correctamente Thumb <br />";
                echo 
$this->carpeta "thumb/" $this->newname "<br />";
            }
        
        }
    }function 
Thumb(){
        
        if (
$this->listo_thumb == true){
                    
            
$this->imagen_thumb imagecreatefromjpeg($this->carpeta $this->newname);
            
            
$this->img_thumb imagecreatetruecolor(150150);
            

            
$this->new_ancho2 imagesx($this->imagen_thumb); 
            
$this->new_alto2 imagesy($this->imagen_thumb);
            
            
            
$this->ancho_thumb_max 150;
            
$this->alto_thumb_max 150;

            if(
$this->ancho_thumb_max/$this->new_ancho2 $this->alto_thumb_max/$this->new_alto2)
            {
                
$this->ancho_thumb $this->ancho_thumb_max;
                
$this->alto_thumb = ($this->new_alto2 $this->ancho_thumb) / $this->new_ancho2;
                
$this->image_x 0;
                
$this->image_y = ($this->alto_thumb_max $this->alto_thumb) / 2;
            }
            else
            {
                
$this->alto_thumb $this->alto_thumb_max;
                
$this->ancho_thumb = ($this->new_ancho2 $this->alto_thumb) / $this->new_alto2;
                
$this->image_y 0;
                
$this->image_x = ($this->ancho_thumb_max $this->ancho_thumb) / 2;
            }

                
            
imagecopyresampled($this->img_thumb$this->imagen_thumb$this->image_x$this->image_y00$this->ancho_thumb$this->alto_thumb$this->new_ancho2$this->new_alto2);
          
            
            
$this->copy_thumb imagejpeg($this->img_thumb,$this->carpeta "thumb/" $this->newname80);
   
            if (
$this->copy_thumb){
                
imagedestroy($this->img_thumb);
                
imagedestroy($this->imagen_thumb);
                
$this->message "Copiado correctamente Thumb <br />";
                echo 
$this->carpeta "thumb/" $this->newname "<br />";
            }
        
        }
    }