Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/10/2010, 08:22
dezagus
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Agregar Código

Se que puede sonar estúpido, pero existen funciones que no entiendo, mas que nada las GD (control de imagenes) soy totalmente nuevo en ello.

Por eso busqué un script en internet, si mal no recuerdo en forosdelweb, y pude encontrar esto:

Código PHP:

## CONFIGURACION ############################# 

    # ruta de la imagen a redimensionar 
    
$imagen=$imgurl
    
# ruta de la imagen final, si se pone el mismo nombre que la imagen, esta se sobreescribe 
    
$imagen_final=$final
    
$ancho_nuevo=$an
    
$alto_nuevo=$al

## FIN CONFIGURACION ############################# 


function redim($ruta1,$ruta2,$ancho,$alto
    { 
    
# se obtene la dimension y tipo de imagen 
    
$datos=getimagesize ($ruta1); 
     
    
$ancho_orig $datos[0]; # Anchura de la imagen original 
    
$alto_orig $datos[1];    # Altura de la imagen original 
    
$tipo $datos[2]; 
     
    if (
$tipo==1){ # GIF 
        
if (function_exists("imagecreatefromgif")) 
            
$img imagecreatefromgif($ruta1); 
        else 
            return 
false
    } 
    else if (
$tipo==2){ # JPG 
        
if (function_exists("imagecreatefromjpeg")) 
            
$img imagecreatefromjpeg($ruta1); 
        else 
            return 
false
    } 
    else if (
$tipo==3){ # PNG 
        
if (function_exists("imagecreatefrompng")) 
            
$img imagecreatefrompng($ruta1); 
        else 
            return 
false
    } 
     
    
# Se calculan las nuevas dimensiones de la imagen 
    
if ($ancho_orig>$alto_orig
        { 
        
$ancho_dest=$ancho
        
$alto_dest=($ancho_dest/$ancho_orig)*$alto_orig
        } 
    else 
        { 
        
$alto_dest=$alto
        
$ancho_dest=($alto_dest/$alto_orig)*$ancho_orig
        } 

    
// imagecreatetruecolor, solo estan en G.D. 2.0.1 con PHP 4.0.6+ 
    
$img2=@imagecreatetruecolor($ancho_dest,$alto_dest) or $img2=imagecreate($ancho_dest,$alto_dest); 

    
// Redimensionar 
    // imagecopyresampled, solo estan en G.D. 2.0.1 con PHP 4.0.6+ 
    
@imagecopyresampled($img2,$img,0,0,0,0,$ancho_dest,$alto_dest,$ancho_orig,$alto_orig) or imagecopyresized($img2,$img,0,0,0,0,$ancho_dest,$alto_dest,$ancho_orig,$alto_orig); 

    
// Crear fichero nuevo, según extensión. 
    
if ($tipo==1// GIF 
        
if (function_exists("imagegif")) 
            
imagegif($img2$ruta2); 
        else 
            return 
false

    if (
$tipo==2// JPG 
        
if (function_exists("imagejpeg")) 
            
imagejpeg($img2$ruta2); 
        else 
            return 
false

    if (
$tipo==3)  // PNG 
        
if (function_exists("imagepng")) 
            
imagepng($img2$ruta2); 
        else 
            return 
false
     
    return 
true
    } 
    
    
redim ($imagen,$imagen_final,$ancho_nuevo,$alto_nuevo); 

// Mostrar Imagen
header"Content-type: image"); 
$imagen_png file_get_contents($final); 
return 
$imagen_png



Lo que hace este script es redimencionar la imagen, en este caso:
JPEG, GIF, PNG.

Mi problema es que no redimenciona JPG y BMP, si alguien me podria ayudar a agregar el código correspondiente para que lo haga se lo agradeceria desde ya.

Mientras me daré una lectura a las funciones que no entiendo como imagejpeg().

Gracias.