Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/02/2011, 11:29
walterdevel
 
Fecha de Ingreso: diciembre-2010
Mensajes: 788
Antigüedad: 13 años, 4 meses
Puntos: 51
Respuesta: Redimensionar imagen con PHP de forma proporcional

Te paso una función para obtener dimensiones proporcionales en base al tamaño real y al máximo que puede tomar ( siempre que sea menor al real ).

Código PHP:
Ver original
  1. function getNewSize($w, $h, $lw, $lh) {
  2.     //obtain an new size from start, max dimesions
  3.     if($w > $lw) {
  4.         $percent = ($lw * 100) / $w;
  5.         $w = $lw;
  6.         $h = $h * ($percent / 100);
  7.     }
  8.     if($h > $lh) {
  9.         $percent = ($lh * 100) / $h;
  10.         $h = $lh;
  11.         $w = $w * ($percent / 100);
  12.     }
  13.     return array('w' => $w, 'h' => $h);
  14. }

Los parámetros son: $w y $h tamaño real ( en este caso, el de tu imagen) y $lw, $lh son el tamaño máximo que puede tomar.