Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/08/2010, 21:13
severicks
 
Fecha de Ingreso: septiembre-2009
Mensajes: 306
Antigüedad: 17 años, 1 mes
Puntos: 10
Problema con este script

Hola.

Estoy haciendo un pequeño CMS que incluye subir fotos para una galeria de imagenes. Leyendo varios tutoriales aquí y allá arme un script para redimensionar o recortar las imagenes segun sea necesario, peor por algun motivo no me funciona.
Este es el script:

Código PHP:
    function crear_thumb($img, $tname){
            
// Obtencion de formatos de imagen 
            
if(stristr(strtolower($img),"jpg") or stristr(strtolower($img),"jpeg")){ 
                
$img = imagecreatefromjpeg($img); 
                
$tipo = "jpg"; 
            } 
    
            if(
stristr(strtolower($img),"png")){ 
                
$img = imagecreatefrompng($img); 
                
$tipo = "png"; 
            } 
             
            if(
stristr(strtolower($img),"gif")){ 
                
$img = imagecreatefromgif($img); 
                
$tipo = "gif"; 
            } 
                 
                    
// Obtenemos ancho y alto de la imagen 
            
$ancho = imagesx($img); 
            
$alto = imagesy($img); 
            echo 
$alto . "<br/>" .$ancho;
            if((
$ancho/$alto <= 1.39) && ($alto/$ancho <=0.8) || ($ancho/$alto <= 0.8) && ($alto/$ancho <=1.88)){
                
$n_alto = 202; 
                
$redu = ($n_alto * 100) / $alto; 
                
$n_ancho = round($ancho * $redu / 100); 
                
$thumb = imagecreatetruecolor($n_ancho,$n_alto); 
                
var_dump($thumb);
                
var_dump($img);
                if(!
imagecopyresized($thumb,$img,0,0,0,0,$n_ancho,$n_alto,$ancho,$alto)){echo "cpy <br/>"; }
                switch(
$tipo){
                    case 
"jpg":echo " JPEGLE ";
                    
$img = imagecreatefromjpeg($tname);
        
                    case 
"png":
                    
$img = imagecreatefrompng($tname);
        
                    case 
"gif":
                    
$img = imagecreatefromgif($tname);
                }
                return array(
$n_ancho, $n_alto);
                echo 
"hola";
            }else{
                
                
$n_alto = 202; 
                
$redu = ($n_alto * 100) / $alto; 
                
$n_ancho = round($ancho * $redu / 100); 
                
$thumb = imagecreatetruecolor($n_ancho,$n_alto); 
                
imagecopyresized($thumb,$img,0,0,0,0,$n_ancho,$n_alto,$ancho,$alto); 
                switch(
$tipo){
                    case 
"jpg":
                    
$img = imagecreatefromjpeg($tname);
        
                    case 
"png":
                    
$img = imagecreatefrompng($tname);
        
                    case 
"gif":
                    
$img = imagecreatefromgif($tname);
                }
                
                
$ancho = imagesx($img);
                
$thumb = imagecreatetruecolor(244, 204);
                if(
imagecopyresampled($thumb, $img, 0, 0, abs(($ancho - 244) / 2),0, 244, 204, 244, 204)){
                    echo 
"aja";
                    switch(
$tipo){
                        case 
"jpg":
                        
imagejpeg($thumb, $tname); 
            
                        case 
"png":
                        
imagepng($thumb, $tname); 
            
                        case 
"gif":
                        
imagegif($thumb, $tname); 
                    }

                }
                return array(
244, 204);
            }

    
            
imagedestroy($thumb); 
    } 
Que estoy haciendo mal? no entiendo por que es que no funciona.
__________________
Mantente al tanto del acontecer Turistico nacional
Visita el Parque Bicentenario El Salvador