Ver Mensaje Individual
  #8 (permalink)  
Antiguo 12/02/2014, 15:24
Avatar de rodrigus71
rodrigus71
 
Fecha de Ingreso: mayo-2012
Ubicación: Alicante
Mensajes: 73
Antigüedad: 14 años, 4 meses
Puntos: 3
Respuesta: Redimensionar imagen con php

Como no consigo saber que falla en el scrip anterior he buscado en la web y he encontrado este que si funciona por si a alguien le interesa, pero aún me queda algo.

Para mostrar la imagen redimensionada quisiera usar algo como esto

Código HTML:
<img src="resize.php?w=140&h=140&i=imagen_original.jpg"> 
pero no se que me faltaría añadir al scrip para que funcione

Código PHP:
$w = $_GET['w'];
$h = $_GET['h'];
$imagen = $_GET['i'];
 
$im = null;
 
if(
stripos($imagen, ".gif")) $im = imagecreatefromgif($imagen);
if(
stripos($imagen, ".jpg")) $im = imagecreatefromjpeg($imagen);
if(
stripos($imagen, ".png")) $im = imagecreatefrompng($imagen);
 
list(
$wi,$hi) = getimagesize($imagen);
$w_scale = $w/$wi;
$h_scale = $h/$hi;
 
if(
$w_scale<$h_scale){
    
$w = $wi*$w_scale;
    
$h = $hi*$w_scale;
}else{
    
$w = $wi*$h_scale;
    
$h = $hi*$h_scale;
}
 
$thumb = imagecreatetruecolor($w,$h);
 
imagecopyresampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $wi, $hi);
header("Content-type: image/jpg");

imagejpeg($thumb);
imagedestroy($thumb); 
__________________
Dame hueco, que habiendo hueco yo ya...
https://www.ofidecoeducativos.es/