Ver Mensaje Individual
  #9 (permalink)  
Antiguo 15/03/2013, 02:48
Avatar de syntex
syntex
 
Fecha de Ingreso: noviembre-2002
Ubicación: Cataluña
Mensajes: 978
Antigüedad: 24 años
Puntos: 4
Thumbnails

Hola muy buenas,

Porque me rellena todo el fondo de color negro el thumbnails?
Más que estoy dando le vueltas no puedo solucionarlo.

Me pueden ayudar?

Código PHP:
class Thumbnails 
{           
    function 
compress()
    {
        if (empty(
$this->quality))
            
$this->quality = 10;
            
        if (empty(
$this->width))
            
$this->width = 200;
            
        if (empty(
$this->height))
            
$this->height = 200;
        
        if (empty(
$this->name_thumnbails))
            
$this->name_thumnbails = $this->name_original;
                
        
$file         = $this->ruta_original.$this->name_original;
        
$savePath   = $this->ruta_original.$this->ruta_thumnbails;
        
        
//Obtenemos la informacion de la imagen, el array info tendra los siguientes indices:
        // 0: ancho de la imagen
         // 1: alto de la imagen
        // mime: el mime_type de la imagen
        
$info = getimagesize($file);
        
        
# Extensión del archivos
        # **********************************************************
        
$extension = explode(".",$this->name_original); 
        
$ext = count($extension)-1; 
                
        
# COMPRIMIR JPG
        # **********************************************************
        
if(strcasecmp($extension[$ext],"jpg") == 0 || strcasecmp($extension[$ext],"jpeg") == 0)
        {
               
$image = imagecreatefromjpeg($file);
        }
        elseif(
strcasecmp($extension[$ext],"png") == 0) 
               
$image = imagecreatefrompng($file);
            
        elseif(
strcasecmp($extension[$ext],"gif") == 0) 
               
$image = imagecreatefromgif($file);
        
        if(
$info[0] == $info[1])
        {
            
$xpos = 0;
            
$ypos = 0;
            
$width  = $info[1];
            
$height = $info[1];
            
        }else{
            
            if(
$info[0] < $info[1])
            {
              
//imagen horizontal
              
$xpos = ceil(($info[0] - $info[1]) /2);
              
$ypos = 0;
              
$width  = $info[1];
              
$height = $info[1];
            }else{
              
//imagen vertical
              
$ypos = ceil(($info[1] - $info[0]) /2);
              
$xpos = 0;
              
$width  = $info[0];
              
$height = $info[0];
            }
        }
        
        
//Creamos una nueva imagen cuadrada con las dimensiones que queremos:
        
$image_new = imagecreatetruecolor($this->width, $this->height);
        
$bgcolor = imagecolorallocate($image_new, 255, 255, 255);
        
imagefilledrectangle($image_new, 0, 0, $this->width, $this->height, $bgcolor); 
        
imagealphablending($image_new, true); 
         
        
//Copiamos la imagen original con las nuevas dimensiones
        
imagecopyresampled($image_new, $image, 0, 0, $xpos, $ypos, $this->width, $this->height, $width, $height);
         
        
//Guardamos la nueva imagen como jpg con una quality del 85%
        
if(strcasecmp($extension[$ext],"jpg") == 0 || strcasecmp($extension[$ext],"jpeg") == 0) 
        {
               if (
$exito = imagejpeg($image_new, $this->ruta_thumnbails.$this->name_thumnbails, $this->quality))
            {                
                
imagedestroy($image_new);
                return 
true; 
            }
        }    
        elseif(
strcasecmp($extension[$ext],"png") == 0) 
        {
               if (
$exito = imagepng($image_new, $this->ruta_thumnbails.$this->name_thumnbails, ($this->quality/10)))
            {
                
imagedestroy($image_new);
                return 
true; 
            }
        }
        elseif(
strcasecmp($extension[$ext],"gif") == 0)
        {
               if (
$exito = imagegif($image_new, $this->ruta_thumnbails.$this->name_thumnbails, $this->quality))
            {
                
imagedestroy($image_new);
                return 
true; 
            }
        }
        elseif(
strcasecmp($extension[$ext],"bmp") == 0)
        {
            
copy ($file, $this->ruta_thumnbails.$this->name_thumnbails);
            return 
true; 
        }
        
        return 
false; 
    }
} 
__________________
------------------------------------------------
La paciencia es el rey de la ciencia
------------------------------------------------