Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/10/2010, 08:15
Avatar de repara2
repara2
 
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 8 meses
Puntos: 331
Respuesta: Redimensionar imagen

Si vas a recibir la imagen por get, lo ideal sería que $_GET['imagen'] contenga el nombre del archivo de imagen y la ruta la pones tú, algo así:

Código PHP:

<?php
$anchura
=180;
$hmax=180;


// $_GET['imagen']) = "icono.gif";
$ruta_imagen "/img/";
$nombre=basename($ruta_imagen.$_GET['imagen']);


$datos getimagesize($nombre);
if(
$datos[2]==1){$img = @imagecreatefromgif($nombre);}
if(
$datos[2]==2){$img = @imagecreatefromjpeg($nombre);}
if(
$datos[2]==3){$img = @imagecreatefrompng($nombre);}
$ratio = ($datos[0] / $anchura);
$altura = ($datos[1] / $ratio);
if(
$altura>$hmax){$anchura2=$hmax*$anchura/$altura;$altura=$hmax;$anchura=$anchura2;}
$thumb imagecreatetruecolor($anchura,$altura);
imagecopyresampled($thumb$img0000$anchura$altura$datos[0], $datos[1]);
if(
$datos[2]==1){header("Content-type: image/gif"); imagegif($thumb);}
if(
$datos[2]==2){header("Content-type: image/jpeg");imagejpeg($thumb);}
if(
$datos[2]==3){header("Content-type: image/png");imagepng($thumb); }
imagedestroy($thumb);
?>