Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/02/2010, 08:15
Avatar de jackson666
jackson666
 
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 6 meses
Puntos: 65
Respuesta: Guardar thumbnails

Te dejo una clase que tenia yo hace tiempo que te la guarda despues de redimensionarla

Código PHP:
class ImgHandler{

    var 
$imagen;//nombre de la imagen cargada
    
var $ext;//extension nueva imagen cargada
    
    
var $ancho;//ancho de nueva imagen
    
var $alto;//alto de nueva imagen
    
    
function __construct($ruta){
        if(
file_exists($ruta)){
        
$this->imagen=$ruta;
    }else{
        echo 
"Ruta de Imagen Incorrecta";
    }
        return 
true;
    }
    
    function 
resizeImg($newName,$width,$height){
        
        
$tamano=getimagesize($this->imagen);
        
$this->ancho=$tamano[0];
        
$this->alto=$tamano[1];
                    
        
$imagenRedim=imagecreatetruecolor($width,$height);      
       
        list(
$nombre,$extension)=explode(".",$this->imagen);
        
$this->ext=$extension;
        
        if(empty(
$newName)){
            
$newName=$nombre;
        }        
        
        echo 
"<br /><b>Nombre de la Imagen Original:</b> ".$this->imagen."<br /><br />";
        echo 
"<b>Nombre de la Imagen Transformada:</b> ".$newName.".".$this->ext."<br /><br />";
        
        echo 
"<u>Tamaño de la Imagen Original:</u><br />Ancho--> ".$tamano[0]."<br />Alto---> ".$tamano[1]."<br /><br />";
        echo 
"<u>Tamaño de la Imagen Transformada:</u><br />Ancho--> ".$width."<br />Alto---> ".$height."<br /><br />";
       
        if(
strtolower($this->ext)=="jpg" or strtolower($this->ext)=="jpeg"){
            
$crear=imagecreatefromjpeg($this->imagen);
            
imagecopyresampled($imagenRedim,$crear,0,0,0,0,$width,$height,$this->ancho,$this->alto);
            
imagejpeg($imagenRedim,$newName.".jpg",100);
            echo 
"Formato---> jpg<br />";
            
imagedestroy($crear);
       
        }else if(
strtolower($this->ext)=="png"){
            echo 
"Formato---> png<br />";
            
$crear=imagecreatefrompng($this->imagen);
            
imagecopyresampled($imagenRedim,$crear,0,0,0,0,$width,$height,$this->ancho,$this->alto);
            
imagepng($imagenRedim,$newName.".png");
            
imagedestroy($crear);
                
        }else if(
strtolower($this->ext)=="gif"){
            echo 
"Formato---> gif<br />";
            
$crear=imagecreatefromgif($this->imagen);
            
imagecopyresampled($imagenRedim,$crear,0,0,0,0,$width,$height,$this->ancho,$this->alto);
            
imagegif($imagenRedim,$newName.".gif");
            
imagedestroy($crear);
        
        }else{
            echo 
"<b><font color='red'>El nombre o extension de la imagen es Incorrecto</font></b>";
        }
       
    }
   
    function 
scaleImg($newName,$percent){
        
       
#echo "<br /><b>Nombre de Imagen:</b> ".$this->imagen."<br />";
        
        
$tamano=getimagesize($this->imagen);
        
$this->ancho=$tamano[0];
        
$this->alto=$tamano[1];
        
        
#Redimension
        
$finalWidth=$this->ancho*$percent;
        
$finalHeight=$this->alto*$percent;
        
        
$imgEscalada=imagecreatetruecolor($finalWidth,$finalHeight);
               
        list(
$noSirve,$sirve)=explode(".",$this->imagen);
        
$this->ext=$sirve;        
       
        if(
strtolower($this->ext)=="jpg" or strtolower($this->ext)=="jpeg"){
            
#echo "Formato---> jpg<br />";
            
$crear=imagecreatefromjpeg($this->imagen);
            
imagecopyresampled($imgEscalada,$crear,0,0,0,0,$finalWidth,$finalHeight,$this->ancho,$this->alto);
            
imagejpeg($imgEscalada,$newName.".jpg",100);
                  
        }else if(
strtolower($this->ext)=="png"){
            
#echo "Formato---> png<br />";
            
$crear=imagecreatefrompng($this->imagen);
            
imagecopyresampled($imgEscalada,$crear,0,0,0,0,$finalWidth,$finalHeight,$this->ancho,$this->alto);
            
imagepng($imgEscalada,$newName.".png");
       
        }else if(
strtolower($this->ext)=="gif"){
            
#echo "Formato---> gif<br />";
            
$crear=imagecreatefromgif($this->imagen);
            
imagecopyresampled($imgEscalada,$crear,0,0,0,0,$finalWidth,$finalHeight,$this->ancho,$this->alto);
            
imagegif($imgEscalada,$newName.".gif");
        }
        
    }

Para usarlo:

Ejemplo de escala

Código PHP:
<?php
include("imghandler.class.php");

$thumb=new ImgHandler("img/1.jpg");

$thumb->scaleImg("1",0.35);
?>
Ejemplo de redimension

Código PHP:
<?php
include("imghandler.class.php");

$thumb=new ImgHandler("img/1.jpg");

$thumb->resizeImg("algo"100100);
?>
Modificalo a gusto para que te lo guarde donde quieras...
__________________
HV Studio
Diseño y desarrollo web