Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/05/2004, 19:15
Avatar de Gerald
Gerald
 
Fecha de Ingreso: julio-2003
Mensajes: 1.356
Antigüedad: 20 años, 9 meses
Puntos: 2
Mas en http://www.php-hispano.net/archivos_tmp/108
Código PHP:
<?php
function normalizar_grafico($size_x,$size_y,$hueco_x,$hueco_y,$extender true) {

    if (
$size_x && $size_y 0) {
     
        if (
$size_x <= $hueco_x && $size_y <= $hueco_y && !$extender) { 
            
$y $size_y
            
$x $size_x
        }
         
        else {
         
            if (
$hueco_x/$size_x $hueco_y/$size_y) { 
                
$x $hueco_x
                
$y $size_y*($hueco_x/$size_x); 
            }
             
            else { 
                
$x $size_x*($hueco_y/$size_y); 
                
$y $hueco_y
            } 
     
        }
         
        
$coord = array (round($x),round($y)); 
        return 
$coord;
    }
    
    else return 
false
}

// Ejemplo de uso:
// Muestra en una pagina una tabla de n x 4 celdas todas las imagenes
// que se encuentren en el directorio donde se ejecuta el script.
// Se ha puesto el borde de la tabla a 1 para que se note 
// el efecto de la redimensión, y cómo se ajustan las imágenes 
// al ancho/alto del hueco especificado.

echo '<table border="1"><tr>';
$dir "./"
$extensiones = array('jpg','jpeg','gif','png');
$dp opendir($dir);
$max_width=100;
$max_height=125;
$i 0;

while (
$file readdir($dp)) {

    if (
$file != '.' && $file != '..' && in_array(strtolower(substr(strrchr($file,'.'),1)),$extensiones)) {
        
// buena idea el strrchr() nils
        
        
$i++;
        
$tamaño=getimagesize($file);
        
$tamaño=normalizar_grafico($tamaño[0],$tamaño[1],$max_width,$max_height,true);
        
        echo 
'<td align="center" width="'.$max_width.'" height="'.$max_height.'">
          <img src="'
.$dir.$file.'" width="'.$tamaño[0].'" height="'.$tamaño[1].'" /></td>'
          
        if (
$i%== 0) echo '</tr><tr>';        
    }
}

echo 
'</tr></table>';
?>
__________________
Solo por Hoy: Trataré de fortalecer mi mente. Estudiaré y aprenderé algo útil
Hoteldipity
Arte Caracol