Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/07/2012, 12:03
alvarols
 
Fecha de Ingreso: diciembre-2008
Mensajes: 738
Antigüedad: 15 años, 5 meses
Puntos: 15
Problemas al tratar de redimensionar imágenes en PHP

Tengo el siguiente código que funciona con la librería GD (que efectivamente tengo instalado en mi servidor), el cual se supone redimensionaría las imágenes. El problema es que si las copia pero no las redimensiona:

Esta es la función:

Código PHP:
<?php
function resizeFit($im,$width,$height) {
    
//Original sizes
    
$ow imagesx($im); $oh imagesy($im);
    
    
//To fit the image in the new box by cropping data from the image, i have to check the biggest prop. in height and width
    
if($width/$ow $height/$oh) {
        
$nw $width;
        
$nh = ($oh $nw) / $ow;
        
$px 0;
        
$py = ($height $nh) / 2;
    } else {
        
$nh $height;
        
$nw = ($ow $nh) / $oh;
        
$py 0;
        
$px = ($width $nw) / 2;
    }
    
    
//Create a new image width requested size
    
$new imagecreatetruecolor($width,$height);
    
    
//Copy the image loosing the least space
    
imagecopyresampled($new$im$px$py00$nw$nh$ow$oh);
    
    return 
$new;
}
?>
Y este es el código que implemento en el formulario en el que lo estoy aplicando que llama a la función. $destino es la variable que contiene la ruta de la imagen original (solo pongo la parte que hace esta función)

Código PHP:
$im imagecreatefromjpeg($destino);
                    
$resized resizeFit($im100150);
                    
imagepng($im,'curri/imagen.png'); 
Ojalá me pudieran ayudar.

Un saludo