Ver Mensaje Individual
  #19 (permalink)  
Antiguo 17/02/2010, 10:10
Avatar de SalomonHe
SalomonHe
 
Fecha de Ingreso: febrero-2010
Mensajes: 28
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Imagenes con PHP

Código HTML:
Ver original
  1. <?php
  2.  
  3. $anchura=110;
  4.  
  5. $hmax=110;
  6.  
  7. $nombre=basename($_GET['imagen']);
  8.  
  9. $datos = getimagesize($nombre);
  10.  
  11. if($datos[2]==1){$img = @imagecreatefromgif($nombre);}
  12.  
  13. if($datos[2]==2){$img = @imagecreatefromjpeg($nombre);}
  14.  
  15. if($datos[2]==3){$img = @imagecreatefrompng($nombre);}
  16.  
  17. $ratio = ($datos[0] / $anchura);
  18.  
  19. $altura = ($datos[1] / $ratio);
  20.  
  21. if($altura>$hmax){$anchura2=$hmax*$anchura/$altura;$altura=$hmax;$anchura=$anchura2;}
  22.  
  23. $thumb = imagecreatetruecolor($anchura,$altura);
  24.  
  25. imagecopyresampled($thumb, $img, 0, 0, 0, 0, $anchura, $altura, $datos[0], $datos[1]);
  26.  
  27. if($datos[2]==1){header("Content-type: image/gif"); imagegif($thumb);}
  28.  
  29. if($datos[2]==2){header("Content-type: image/jpeg");imagejpeg($thumb);}
  30.  
  31. if($datos[2]==3){header("Content-type: image/png");imagepng($thumb); }
  32.  
  33. imagedestroy($thumb);
  34.  
  35. ?>