[ayuda] problema con script en php que redimenciona imagenes!

Buenas tengo un script que les dejo a continuacion para redimencionar las imagenes, FUNCIONA BARBARO! el problema es que las imagenes PNG con fondo transparente cuando la redimenciones a tamaños muy pequeños ejemplo 150px x 150px el fondo transparente se vuelve negro! porque será? habra alguna manera de solucionarlo?
<?PHP
function cambiartam($nombre,$archivo,$ancho,$alto)
    {
    $tmp=explode(".",$nombre);
    $partes=sizeof($tmp);
    $tmp=$tmp[$partes-1];

    if (preg_match('/jpg|jpeg|JPG/',$tmp))
        {
        $imagen=imagecreatefromjpeg($nombre);
        }
    if (preg_match('/png|PNG/',$tmp))
        {
        $imagen=imagecreatefrompng($nombre);
        }
    if (preg_match('/gif|GIF/',$tmp))
        {
        $imagen=imagecreatefromgif($nombre);
        }

    $x=imageSX($imagen);
    $y=imageSY($imagen);

    if ($x > $y) 
        {
        $w=$ancho;
        $h=$y*($alto/$x);
        }

    if ($x < $y) 
        {
        $w=$x*($ancho/$y);
        $h=$alto;
        }

    if ($x == $y) 
        {
        $w=$ancho;
        $h=$alto;
        }


    $destino=ImageCreateTrueColor($w,$h);
    imagecopyresampled($destino,$imagen,0,0,0,0,$w,$h,$x,$y); 


    if (preg_match("/png/",$tmp))
        {
        imagepng($destino,$archivo); 
        } 
    if (preg_match("/gif/",$tmp))
        {
        imagegif($destino,$archivo);
        }
    else 
        {
        imagejpeg($destino,$archivo); 
        }

    imagedestroy($destino); 
    imagedestroy($imagen); 
}
?>
Hola:

Esto sí funciona:

<?php
  // Se utiliza así:
  $imagen = 'imagen.png';
  // (Obligatorio) Nombre y ruta de la imagen.
  // (Obligatorio) Un array con el ancho y alto (es un entero).
  // (Opcional) Un nombre alternativo para la nueva imagen.
  $obj = new IMGResizer( $imagen, array( ancho, alto ) );
  // $obj->resize() devuelve el nombre del archivo nuevo (si es que se especificó).
  echo $obj->resize();

class IMGResizer {
		/**
		 * The image file path.
		 * @var String.
		 */
		private $image	 = null;
		
		/**
		 * Original image Width.
		 * @var Integer.
		 */
		private $owidth	 = 0;
		
		/**
		 * Original image Height.
		 * @var Integer.
		 */
		private $oheight = 0;
		
		/**
		 * Image file type (png, jpeg, jpg, gif, etc.). Currently only supports gif, png and jp(e)g.
		 * @var String.
		 */
		private $imgType = '';
		
		/**
		 * Resize width.
		 * @var Integer.
		 */
		private $nwidth	 = 0;
		
		/**
		 * Resize height.
		 * @var Integer
		 */
		private $nheight = 0;
		
		/**
		 * Resized File name.
		 * @var String.
		 */
		private $newFile = '';
		
		/**
		 * Image File base directory.
		 * @var String.
		 */
		private $path		 = '';
		
		/**
		 * A class to resize images.
		 * @param String $imagePath - The image file name and path.
		 * @param Integer[] $newSize - $newSize[0] is the width and $newSize[1] is the height.
		 * @param String $resizedFileName - Optional; if not specified, the original filename will be used.
		 */
		public function __construct( $imagePath, $newSize, $resizedFileName = '' ) {
			$this->image	 = $imagePath;
			$data 				 = getimagesize( $imagePath );
			$this->owidth	 = $data[0];
			$this->oheight = $data[1];
			$tmp 					 = explode( '/', $data['mime'] );
			$this->imgType = $tmp[1];
			$this->nwidth	 = $newSize[0];
			$this->nheight = $newSize[1];
			
			if( $resizedFileName )
				$this->newFile = $resizedFileName;
			else
				$this->newFile = basename( $imagePath );
			
			$this->path 	 = dirname( $imagePath );
		}
		
		/**
		 * @return String - Returns the new image file name.
		 */
		public function resize() {
			$target = null;
			$source = null;
			$file 	= "$this->path/$this->newFile";
			switch( $this->imgType ) {
				case 'png':
					$source = imagecreatefrompng( $this->image );
					$target = $this->getResizedResource();
					imagealphablending( $target, false );
					imagesavealpha( $target, true );
					$transparent = imagecolorallocatealpha( $target, 255, 255, 255, 127 );
					imagefilledrectangle( $target, 0, 0, $this->nwidth, $this->nheight, $transparent );
					imagecopyresampled( $target, $source, 0, 0, 0, 0, $this->nwidth, $this->nheight, $this->owidth, $this->oheight );
					imagepng( $target, $file );
					break;
			
				case 'jpeg':
				case 'jpg':
					$target = $this->getResizedResource();
					imagejpeg( $target, $file );
					break;
			
				case 'gif':
					$target = $this->getResizedResource();
					imagegif( $target, $file );
					break;
			}
				
			if( $target !== null )
				imagedestroy( $target );
			
			chmod( $file, 0644 );
			return $this->newFile;
		}
		
		/**
		 * Creates a true color image with the values of $newSize param.
		 * @param Integer[] $origSize - Original Width and Height
		 * @param Integer[] $newSize - New width and height.
		 * @return Resource - Returns a resized image resource.
		 */
		public function getResizedResource() {
			$w = 0;
			$h = 0;
			$x = $this->owidth;
			$y = $this->oheight;
			
			if( $x > $y ) {
				$w = $this->nwidth;
				$h = $y * ( $this->nheight / $x );
			} else if( $x < $y ) {
				$w = $w * ( $this->nwidth / $y );
				$h = $this->nheight;
			} else {
				$w = $this->nwidth;
				$h = $this->nheight;
			}
			
			return imagecreatetruecolor( $w, $h );
		}
	}
?>

Ahí me cuentas como te va.
Muchas gracias por tu ayuda skaparate, pero no se como usar tu codigo! :/ perdon la ignorancia, viste que en el que tengo tiene solamente la funcion esa, entonces lo que hago es un documento.php para que verifique las cajas del formulario, y que cargue en la base, y que mueva la imagen a la carpeta de destino, y ahi llamo una vez a la funcion para crear la imagen en miniatura, y despues verifico las dimenciones de la imagene y si es mas grande del tamaño por defecto llamo de nuevo a la funcion, pero pasandole otros parametros, como seria eso con tu codigo? (si no es tanta molestia), muchas gracias. y felices fiestas! :)
Hmmm... es simple, en lugar de la llamada a la función cambiartam, reemplaza el código por esto (la clase - class IMGResizer { ... } - debe estar en el mismo archivo):

// ... Antes de esto compruebas los campos del formulario y demás

// Suponiendo que el archivo se suba por el usuario:
$imgName = $_FILES['name_formulario_html']['name'];
move_uploaded_file( $_FILES['name_formulario_html']['tmp_name'], "subidas/$imgName" ); // Se mueve el archivo temporal para darle el nombre que el usuario quiere.

// Con un if... else verificas "las dimensiones de la imágenes"
if( ancho > XXX && alto > XXX ) {
  $ancho = NNN;
  $alto = NNN;
}
// Aquí no se hace nada, solo se crea el objeto con los valores.
$obj = new IMGResizer( "subidas/$imgName", array( $ancho, $alto ), "thumbnail-$imgName" );
// Esta es la función que redimensiona las imágenes:
$obj->resize();
// Si necesitas utilizar otro tamaño, entonces llamas a $obj->setNewSizes():
$obj->setNewSizes( array( $ancho, $alto );
// Y luego vuelves a llamar a resize:
$obj->resize();

// De esta forma el objeto se crea una sola vez :).

class IMGResizer { 
        /** 
         * The image file path. 
         * @var String. 
         */ 
        private $image     = null; 
         
        /** 
         * Original image Width. 
         * @var Integer. 
         */ 
        private $owidth     = 0; 
         
        /** 
         * Original image Height. 
         * @var Integer. 
         */ 
        private $oheight = 0; 
         
        /** 
         * Image file type (png, jpeg, jpg, gif, etc.). Currently only supports gif, png and jp(e)g. 
         * @var String. 
         */ 
        private $imgType = ''; 
         
        /** 
         * Resize width. 
         * @var Integer. 
         */ 
        private $nwidth     = 0; 
         
        /** 
         * Resize height. 
         * @var Integer 
         */ 
        private $nheight = 0; 
         
        /** 
         * Resized File name. 
         * @var String. 
         */ 
        private $newFile = ''; 
         
        /** 
         * Image File base directory. 
         * @var String. 
         */ 
        private $path         = ''; 
         
        /** 
         * A class to resize images. 
         * @param String $imagePath - The image file name and path. 
         * @param Integer[] $newSize - $newSize[0] is the width and $newSize[1] is the height. 
         * @param String $resizedFileName - Optional; if not specified, the original filename will be used. 
         */ 
        public function __construct( $imagePath, $newSize, $resizedFileName = '' ) { 
            $this->image     = $imagePath; 
            $data                  = getimagesize( $imagePath ); 
            $this->owidth     = $data[0]; 
            $this->oheight = $data[1]; 
            $tmp                      = explode( '/', $data['mime'] ); 
            $this->imgType = $tmp[1]; 
            $this->nwidth     = $newSize[0]; 
            $this->nheight = $newSize[1]; 
             
            if( $resizedFileName ) 
                $this->newFile = $resizedFileName; 
            else 
                $this->newFile = basename( $imagePath ); 
             
            $this->path      = dirname( $imagePath ); 
        } 
         
        /** 
         * @return String - Returns the new image file name. 
         */ 
        public function resize() { 
            $target = null; 
            $source = null; 
            $file     = "$this->path/$this->newFile"; 
            switch( $this->imgType ) { 
                case 'png': 
                    $source = imagecreatefrompng( $this->image ); 
                    $target = $this->getResizedResource(); 
                    imagealphablending( $target, false ); 
                    imagesavealpha( $target, true ); 
                    $transparent = imagecolorallocatealpha( $target, 255, 255, 255, 127 ); 
                    imagefilledrectangle( $target, 0, 0, $this->nwidth, $this->nheight, $transparent ); 
                    imagecopyresampled( $target, $source, 0, 0, 0, 0, $this->nwidth, $this->nheight, $this->owidth, $this->oheight ); 
                    imagepng( $target, $file ); 
                    break; 
             
                case 'jpeg': 
                case 'jpg': 
                    $target = $this->getResizedResource(); 
                    imagejpeg( $target, $file ); 
                    break; 
             
                case 'gif': 
                    $target = $this->getResizedResource(); 
                    imagegif( $target, $file ); 
                    break; 
            } 
                 
            if( $target !== null ) 
                imagedestroy( $target ); 
             
            chmod( $file, 0644 ); 
            return $this->newFile; 
        } 
         
        /** 
         * Creates a true color image with the values of $newSize param. 
         * @param Integer[] $origSize - Original Width and Height 
         * @param Integer[] $newSize - New width and height. 
         * @return Resource - Returns a resized image resource. 
         */ 
        public function getResizedResource() { 
            $w = 0; 
            $h = 0; 
            $x = $this->owidth; 
            $y = $this->oheight; 
             
            if( $x > $y ) { 
                $w = $this->nwidth; 
                $h = $y * ( $this->nheight / $x ); 
            } else if( $x < $y ) { 
                $w = $w * ( $this->nwidth / $y ); 
                $h = $this->nheight; 
            } else { 
                $w = $this->nwidth; 
                $h = $this->nheight; 
            } 
             
            return imagecreatetruecolor( $w, $h ); 
        }

        public function setNewSizes( $nsize ) {
          if( is_array( $nsize ) && is_numeric( $nsize[0] ) && is_numeric( $nsize[1] ) ) {
            $this->nwidth = $nsize[0];
            $this->nheight = $nsize[1];
          }
        }
    }
?>

Si no entiendes, entonces deberás mostrarme tu código para ver como hacerlo calzar.
Estoy probando, no logre hacerlo funcionar todavia! :( asi que te voy a dejar mi codigo, pero seguiré intentandolo, y si logro hacerlo funcionar te aviso (si yo funciono jaja) me complica el tema de la clase, es no lo manejo, por eso me cuesta mucho, Bueno este es el .php que sube la imagen al directorio etc ect
<?PHP
include("conexion.php");
include("redimencionar.php");
mysql_select_db($base, $conexion);
$nombre = $_POST['nombre'];
$imagen = $_FILES['imagen']['type'];
$descripcion = $_POST['descripcion'];
$precio = $_POST['precio'];
$oferta = $_POST['oferta'];
$codigo_categoria = $_POST['codigo_categoria'];
$enviar = $_POST['enviar'];
if ($enviar){
	if (strlen($nombre) <= 3){
		echo "En nombre del articulo debe ser mayor a 3 caracteres";
	}else{
		if ($precio < 0.5){
			echo "Ingrese un precio valido para el articulo";
		}else{	
			$mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png", "image/jpg",);
			$url = "imagenes/".$_FILES['imagen']['name'];
			$url = str_replace(' ', '', $url);//eliminar espacios en blancos
			if(!is_uploaded_file($_FILES['imagen']['tmp_name']) or !in_array($imagen, $mimetypes)){
				echo "Por favor elija una imagen con extension: jpg, gif, png o jpeg.";
			}else{
				mysql_select_db ($base, $conexion);
				$sql = "insert into producto (nombre, descripcion, imagen, precio, oferta, codigo_categoria) "."values ('$nombre', '$descripcion', '$url', '$precio', '$oferta', '$codigo_categoria')";
				$result = mysql_query($sql); 		
				move_uploaded_file($_FILES['imagen']['tmp_name'],$url);
				$tam=getimagesize($url);
				if($tam[0] > 125 OR $tam[1] > 125)
				{
					cambiartam($url, $url, 125, 125);
				}	
				header('Location: /3/catalogo/gestion_producto.php?codigo_categoria='.$codigo_categoria);
			}
		}
	}
}
?>
y este es el formulario para subir:
<form action="nuevo_producto.php" method="post" enctype="multipart/form-data" name="nuevo_producto">
  <div class="for">
  <label for="nombre">nombre: </label>
  <input name="nombre" type="text" class="espacio" id="nombre" maxlength="40" /><br />
  <label for="precio">precio: &nbsp;&nbsp;</label>
  <input name="precio" type="text" class="espacio" id="precio" maxlength="8"/><br />
  <label for="imagen"></label><br />
  <label for="imagen">imagen: &nbsp;</label>
  <input type="file" name="imagen" id="imagen" size="10" class="file"/><br />
  <label for="oferta">Producto en oferta</label>
  <input type="radio" name="oferta" id="oferta" value="si" class="espacio"/>
  <label for="oferta">si </label>
  <input type="radio" name="oferta" id="oferta2" value="no" class="espacio" checked/>
  <label for="oferta2"> no</label><br />

  </div>
  <div class="for">
  <label for="descripcion">descripcion</label>
  <textarea name="descripcion" id="descripcion" cols="30" rows="3" class="text" maxlength="80"></textarea><br />
 [PHP] 
  <?PHP
	echo "<input name='codigo_categoria' type='hidden' value=".'"'.$codigo_categoria.'"'." />"
  ?>
[/PHP]
  <input type="submit" name="enviar" id="enviar" value="Enviar" class="boton"/>
  </div>
</form>
perdona tantas molestias, y muchas gracias por la ayuda y la paciencia! :)
No es difícil, de hecho, es casi igual:

<?PHP
include("conexion.php");
//include("redimencionar.php"); // Ya que no se utilizará, se comenta :P.
mysql_select_db($base, $conexion);
$nombre = $_POST['nombre'];
$imagen = $_FILES['imagen']['type'];
$descripcion = $_POST['descripcion'];
$precio = $_POST['precio'];
$oferta = $_POST['oferta'];
$codigo_categoria = $_POST['codigo_categoria'];
$enviar = $_POST['enviar'];
if ($enviar){
    if (strlen($nombre) <= 3){
        echo "En nombre del articulo debe ser mayor a 3 caracteres";
    }else{
        if ($precio < 0.5){
            echo "Ingrese un precio valido para el articulo";
        }else{    
            $mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png", "image/jpg",);
            $url = "imagenes/".$_FILES['imagen']['name'];
            $url = str_replace(' ', '', $url);//eliminar espacios en blancos
            if(!is_uploaded_file($_FILES['imagen']['tmp_name']) or !in_array($imagen, $mimetypes)){
                echo "Por favor elija una imagen con extension: jpg, gif, png o jpeg.";
            }else{
                mysql_select_db ($base, $conexion);
                $sql = "insert into producto (nombre, descripcion, imagen, precio, oferta, codigo_categoria) "."values ('$nombre', '$descripcion', '$url', '$precio', '$oferta', '$codigo_categoria')";
                $result = mysql_query($sql);         
                move_uploaded_file($_FILES['imagen']['tmp_name'],$url);
                $tam=getimagesize($url);
                if($tam[0] > 125 OR $tam[1] > 125)
                {
                    // Eso es todo:
                    $obj = new IMGResizer( $url, array( 125, 125 ) );
                    $obj->resize();
                }    
                header('Location: /3/catalogo/gestion_producto.php?codigo_categoria='.$codigo_categoria);
            }
        }
    }
}

class IMGResizer { 
        /** 
         * The image file path. 
         * @var String. 
         */ 
        private $image     = null; 
         
        /** 
         * Original image Width. 
         * @var Integer. 
         */ 
        private $owidth     = 0; 
         
        /** 
         * Original image Height. 
         * @var Integer. 
         */ 
        private $oheight = 0; 
         
        /** 
         * Image file type (png, jpeg, jpg, gif, etc.). Currently only supports gif, png and jp(e)g. 
         * @var String. 
         */ 
        private $imgType = ''; 
         
        /** 
         * Resize width. 
         * @var Integer. 
         */ 
        private $nwidth     = 0; 
         
        /** 
         * Resize height. 
         * @var Integer 
         */ 
        private $nheight = 0; 
         
        /** 
         * Resized File name. 
         * @var String. 
         */ 
        private $newFile = ''; 
         
        /** 
         * Image File base directory. 
         * @var String. 
         */ 
        private $path         = ''; 
         
        /** 
         * A class to resize images. 
         * @param String $imagePath - The image file name and path. 
         * @param Integer[] $newSize - $newSize[0] is the width and $newSize[1] is the height. 
         * @param String $resizedFileName - Optional; if not specified, the original filename will be used. 
         */ 
        public function __construct( $imagePath, $newSize, $resizedFileName = '' ) { 
            $this->image     = $imagePath; 
            $data                  = getimagesize( $imagePath ); 
            $this->owidth     = $data[0]; 
            $this->oheight = $data[1]; 
            $tmp                      = explode( '/', $data['mime'] ); 
            $this->imgType = $tmp[1]; 
            $this->nwidth     = $newSize[0]; 
            $this->nheight = $newSize[1]; 
             
            if( $resizedFileName ) 
                $this->newFile = $resizedFileName; 
            else 
                $this->newFile = basename( $imagePath ); 
             
            $this->path      = dirname( $imagePath ); 
        } 
         
        /** 
         * @return String - Returns the new image file name. 
         */ 
        public function resize() { 
            $target = null; 
            $source = null; 
            $file     = "$this->path/$this->newFile"; 
            switch( $this->imgType ) { 
                case 'png': 
                    $source = imagecreatefrompng( $this->image ); 
                    $target = $this->getResizedResource(); 
                    imagealphablending( $target, false ); 
                    imagesavealpha( $target, true ); 
                    $transparent = imagecolorallocatealpha( $target, 255, 255, 255, 127 ); 
                    imagefilledrectangle( $target, 0, 0, $this->nwidth, $this->nheight, $transparent ); 
                    imagecopyresampled( $target, $source, 0, 0, 0, 0, $this->nwidth, $this->nheight, $this->owidth, $this->oheight ); 
                    imagepng( $target, $file ); 
                    break; 
             
                case 'jpeg': 
                case 'jpg': 
                    $target = $this->getResizedResource(); 
                    imagejpeg( $target, $file ); 
                    break; 
             
                case 'gif': 
                    $target = $this->getResizedResource(); 
                    imagegif( $target, $file ); 
                    break; 
            } 
                 
            if( $target !== null ) 
                imagedestroy( $target ); 
             
            chmod( $file, 0644 ); 
            return $this->newFile; 
        } 
         
        /** 
         * Creates a true color image with the values of $newSize param. 
         * @param Integer[] $origSize - Original Width and Height 
         * @param Integer[] $newSize - New width and height. 
         * @return Resource - Returns a resized image resource. 
         */ 
        public function getResizedResource() { 
            $w = 0; 
            $h = 0; 
            $x = $this->owidth; 
            $y = $this->oheight; 
             
            if( $x > $y ) { 
                $w = $this->nwidth; 
                $h = $y * ( $this->nheight / $x ); 
            } else if( $x < $y ) { 
                $w = $w * ( $this->nwidth / $y ); 
                $h = $this->nheight; 
            } else { 
                $w = $this->nwidth; 
                $h = $this->nheight; 
            } 
             
            return imagecreatetruecolor( $w, $h ); 
        }

        public function setNewSizes( $nsize ) {
          if( is_array( $nsize ) && is_numeric( $nsize[0] ) && is_numeric( $nsize[1] ) ) {
            $this->nwidth = $nsize[0];
            $this->nheight = $nsize[1];
          }
        }
    }
?>

Ahora, la clase podría ir en el archivo que incluyes con la función para redimensionar en lugar del final del script.
ahora que veo como lo hiciste, no es tan dificil habia sido! jaja (yo estaba haciendo cualquier cosa) por eso no andaba jaja, probe una imagen png con fondo transparente y funciono barbaro, pero las gif y jpg se convierten totalmente en negro! :S copie asi como vos me lo pasaste no le toque nada! que sera? muchas gracias de nuevo!
Jajajajaj, cosas que pasan... se me olvidó incluir una parte en el resto de las imágenes XD (la que actualmente creaba la nueva imagen). Aquí esta la nueva clase:

class IMGResizer {
		/**
		 * The image file path.
		 * @var String.
		 */
		private $image	 = null;
		
		/**
		 * Original image Width.
		 * @var Integer.
		 */
		private $owidth	 = 0;
		
		/**
		 * Original image Height.
		 * @var Integer.
		 */
		private $oheight = 0;
		
		/**
		 * Image file type (png, jpeg, jpg, gif, etc.). Currently only supports gif, png and jp(e)g.
		 * @var String.
		 */
		private $imgType = '';
		
		/**
		 * Resize width.
		 * @var Integer.
		 */
		private $nwidth	 = 0;
		
		/**
		 * Resize height.
		 * @var Integer
		 */
		private $nheight = 0;
		
		/**
		 * Resized File name.
		 * @var String.
		 */
		private $newFile = '';
		
		/**
		 * Image File base directory.
		 * @var String.
		 */
		private $path		 = '';
		
		/**
		 * A class to resize images.
		 * @param String $imagePath - The image file name and path.
		 * @param Integer[] $newSize - $newSize[0] is the width and $newSize[1] is the height.
		 * @param String $resizedFileName - Optional; if not specified, the original filename will be used.
		 */
		public function __construct( $imagePath, $newSize, $resizedFileName = '' ) {
			$this->image	 = $imagePath;
			$data 				 = getimagesize( $imagePath );
			$this->owidth	 = $data[0];
			$this->oheight = $data[1];
			$tmp 					 = explode( '/', $data['mime'] );
			$this->imgType = $tmp[1];
			$this->nwidth	 = $newSize[0];
			$this->nheight = $newSize[1];
			
			if( $resizedFileName )
				$this->newFile = $resizedFileName;
			else
				$this->newFile = basename( $imagePath );
			
			$this->path 	 = dirname( $imagePath );
		}
		
		/**
		 * @return String - Returns the new image file name.
		 */
		public function resize() {
			$target = null;
			$source = null;
			$fsave 	= "$this->path/$this->newFile";
			
			switch( $this->imgType ) {
				case 'png':
					$source = imagecreatefrompng( $this->image );
					$target = $this->getResizedResource();
					imagealphablending( $target, false );
					imagesavealpha( $target, true );
					$transparent = imagecolorallocatealpha( $target, 255, 255, 255, 127 );
					imagefilledrectangle( $target, 0, 0, $this->nwidth, $this->nheight, $transparent );
					$this->resample( $target, $source );
					imagepng( $target, $fsave );
					break;
			
				case 'jpeg':
				case 'jpg':
					$target = $this->getResizedResource();
					$source = imagecreatefromjpeg( $this->image );
					$this->resample( $target, $source );
					imagejpeg( $target, $fsave );
					break;
			
				case 'gif':
					$target = $this->getResizedResource();
					$source = imagecreatefromgif( $this->image );
					$this->resample( $target, $source );
					imagegif( $target, $fsave );
					break;
			}
				
			if( $target !== null )
				imagedestroy( $target );
			
			if( $source !== null )
				imagedestroy( $source );
			
			chmod( $fsave, 0644 );
			return $this->newFile;
		}
		
		/**
		 * Creates a true color image with the values of $newSize param.
		 * @param Integer[] $origSize - Original Width and Height
		 * @param Integer[] $newSize - New width and height.
		 * @return Resource - Returns a resized image resource.
		 */
		public function getResizedResource() {
			$w = 0;
			$h = 0;
			$x = $this->owidth;
			$y = $this->oheight;
			
			if( $x > $y ) {
				$w = $this->nwidth;
				$h = $y * ( $this->nheight / $x );
			} else if( $x < $y ) {
				$w = $w * ( $this->nwidth / $y );
				$h = $this->nheight;
			} else {
				$w = $this->nwidth;
				$h = $this->nheight;
			}
			
			return imagecreatetruecolor( $w, $h );
		}
		
		/**
		 * Sets the image and path of the image to be resized.
		 * @param String $imagePath - The image path and file name.
		 */
		public function setImageAndPath( $imagePath ) {
			if( is_string( $imagePath ) ) {
				$this->image	 = $imagePath;
				$data 				 = getimagesize( $imagePath );
				$this->owidth	 = $data[0];
				$this->oheight = $data[1];
				$tmp 					 = explode( '/', $data['mime'] );
				$this->imgType = $tmp[1];
				$this->path 	 = dirname( $imagePath );
			}
		}
		
		/**
		 * Sets the resized image name.
		 * @param String $name - Only the resized file name (not the path).
		 */
		public function setResizedImageName( $name ) {
			if( preg_match( '/^[\w\.\-_]+$/', $name ) ) {
				$position			 = strrchr( $name, '.' );
				$this->newFile = preg_replace( "/$position/", '', $name );
			}
		}
		
		/**
		 * Set the new sizes.
		 * @param Integer[] $sizes - Set the new sizes to be used when resizing the image.
		 */
		public function setNewSizes( $sizes ) {
			if( is_array( $sizes ) && IMGResizer::areNumeric( $sizes ) ) {
				if( isset( $sizes['width'] ) && isset( $sizes['height'] ) ) {
					$this->nwidth = $sizes['width'];
					$this->nheight = $sizes['height'];
				} else {
					$this->nwidth = $sizes[0];
					$this->nheight = $sizes[1];
				}
			}
		}
		
		/**
		 * Checks whether or not the array contains only numbers or not.
		 * @param Mixed[] $array - The array to check.
		 * @return Boolean - True, if the array contains only numbers, false otherwise.
		 */
		public static function areNumeric( $array ) {
			$ret = true;
					
			if( ! is_array( $array ) ) {
				$ret &= is_numeric( $array );
			} else {
				foreach( $array as $element ) {
					if( is_array( $element ) ) {
						$ret &= areNumeric( $element );
					} else {
						$ret &= is_numeric( $element );
					}
					
					if( ! $ret )
						break;
				}
			}
					
			return $ret;
		}
		
		/**
		 * Wrapper arround imagecopyresampled.
		 * Uses the new image width (set with the class constructor or with setNewSizes( $sizes ) method) and the current image height and width.
		 * @param Resource $target - The target image resource.
		 * @param Resource $source - Original Image resource.
		 * @param Integer[] $coords - The coordinates to be used. The first 2 
		 * elements are the target coordinates and the last 2, the source image coordinates.
		 * @return Boolean | NULL - NULL if the $target or $source are not resources; True if
		 * the image was resampled or false if there was an error.
		 */
		public function resample( $target, $source, $coords = array() ) {
			if( is_resource( $target ) && is_resource( $source ) ) {
				$tx = 0;
				$ty = 0;
				$sx = 0;
				$sy = 0;
				
				if( ! empty( $coords ) && count( $coords ) == 4 ) {
					$tx = $coords[0];
					$ty = $coords[1];
					$sx = $coords[2];
					$sy = $coords[3];
				}
				
				return imagecopyresampled( $target, $source, $tx, $ty, $sx, $sy, $this->nwidth, $this->nheight, $this->owidth, $this->oheight );
			}
			
			return null;
		}
	}

Copia y pega la clase donde puse la otra en mi publicación anterior :P. Aquí hay un ejemplo para cualquiera que lo quiera usar:

Estructura de las carpetas

images - Contendrá todas las imágenes.
includes - Contendrá los archivos php (en este caso, la clase - imgresizer.php - y el script que procesa los datos - get.php).
index.php - El archiv principal.

index.php
<!DOCTYPE html>
<html>
  <head>
    <title>Image Resizer</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">
      jQuery(document).ready(function($) {
	$('input[name=fname]').val($('#file-name').val());
	$('#file-name').change(function(e) {
	  $('input[name=fname]').val($(this).val());
	});
      });
  </head>
  <body>
  <?php
    // Esta función simplemente crea un <select> con las imágenes que existen en la carpeta images.
    function create_select() {
      $dir = 'images';
      $out = '';

      if( $dh = opendir( $dir ) ) {
        $out = '<select id="file-name">';
        while( ( $file = readdir( $dh ) ) !== false ) {
	  if( $file != '..' && $file != '.' && ! preg_match( '/resized.+/', $file ) ) {
	    $out .= "<option value='$file'>$file</option>";
	  }
	}

        $out .= '</select>';
      }

      echo $out;
    }

    create_select();
  ?>

    <form action="includes/get.php" method="get">
      <label for="fname">Nombre del Archivo: <input type="text" name="fname" /></label>
      <label for="fsize">Tama&ntilde;o nuevo (ejemplo: 328x200): </label><input type="text" name="fsize" />
      <input type="submit" />
    </form>
		
    <?php
      function show_resized_images() {
        $dir = 'images';
	$out = '';
				
	if( $dh = opendir( $dir ) ) {
	  $out = "";
			
	  while( ( $file = readdir( $dh ) ) !== false ) {
	    if( $file != '..' && $file != '.' && preg_match( '/resized.+/', $file ) ) {
	      $out .= "<img src='images/$file' />";
	    }
	  }
	}
				
	if( empty( $out ) )
	  $out = 'No hay im&aacute;genes redimensionadas.';
			
	echo $out;
      }
			
      show_resized_images();
    ?>
  </body>
</html>

get.php
<?php
  $root = '..';
  include_once 'imgresizer.php';
  $dir	      = $root . '/images';
  $file      = $dir . '/' . $_GET['fname'];
  $resizer = new IMGResizer( $file, explode( 'x', $_GET['fsize'] ), "resized-$_GET[fname]" );
  $resizer->resize();
  header( "Location: http://localhost/" ); // Si utilizan un servidor local, entonces localhost estará bien, de lo contrario, cambien la URL por la que deseen.
?>

imgresizer.php
<?php
	class IMGResizer {
		/**
		 * The image file path.
		 * @var String.
		 */
		private $image	 = null;
		
		/**
		 * Original image Width.
		 * @var Integer.
		 */
		private $owidth	 = 0;
		
		/**
		 * Original image Height.
		 * @var Integer.
		 */
		private $oheight = 0;
		
		/**
		 * Image file type (png, jpeg, jpg, gif, etc.). Currently only supports gif, png and jp(e)g.
		 * @var String.
		 */
		private $imgType = '';
		
		/**
		 * Resize width.
		 * @var Integer.
		 */
		private $nwidth	 = 0;
		
		/**
		 * Resize height.
		 * @var Integer
		 */
		private $nheight = 0;
		
		/**
		 * Resized File name.
		 * @var String.
		 */
		private $newFile = '';
		
		/**
		 * Image File base directory.
		 * @var String.
		 */
		private $path		 = '';
		
		/**
		 * A class to resize images.
		 * @param String $imagePath - The image file name and path.
		 * @param Integer[] $newSize - $newSize[0] is the width and $newSize[1] is the height.
		 * @param String $resizedFileName - Optional; if not specified, the original filename will be used.
		 */
		public function __construct( $imagePath, $newSize, $resizedFileName = '' ) {
			$this->image	 = $imagePath;
			$data 				 = getimagesize( $imagePath );
			$this->owidth	 = $data[0];
			$this->oheight = $data[1];
			$tmp 					 = explode( '/', $data['mime'] );
			$this->imgType = $tmp[1];
			$this->nwidth	 = $newSize[0];
			$this->nheight = $newSize[1];
			
			if( $resizedFileName )
				$this->newFile = $resizedFileName;
			else
				$this->newFile = basename( $imagePath );
			
			$this->path 	 = dirname( $imagePath );
		}
		
		/**
		 * @return String - Returns the new image file name.
		 */
		public function resize() {
			$target = null;
			$source = null;
			$fsave 	= "$this->path/$this->newFile";
			
			switch( $this->imgType ) {
				case 'png':
					$source = imagecreatefrompng( $this->image );
					$target = $this->getResizedResource();
					imagealphablending( $target, false );
					imagesavealpha( $target, true );
					$transparent = imagecolorallocatealpha( $target, 255, 255, 255, 127 );
					imagefilledrectangle( $target, 0, 0, $this->nwidth, $this->nheight, $transparent );
					$this->resample( $target, $source );
					imagepng( $target, $fsave );
					break;
			
				case 'jpeg':
				case 'jpg':
					$target = $this->getResizedResource();
					$source = imagecreatefromjpeg( $this->image );
					$this->resample( $target, $source );
					imagejpeg( $target, $fsave );
					break;
			
				case 'gif':
					$target = $this->getResizedResource();
					$source = imagecreatefromgif( $this->image );
					$this->resample( $target, $source );
					imagegif( $target, $fsave );
					break;
			}
				
			if( $target !== null )
				imagedestroy( $target );
			
			if( $source !== null )
				imagedestroy( $source );
			
			chmod( $fsave, 0644 );
			return $this->newFile;
		}
		
		/**
		 * Creates a true color image with the values of $newSize param.
		 * @param Integer[] $origSize - Original Width and Height
		 * @param Integer[] $newSize - New width and height.
		 * @return Resource - Returns a resized image resource.
		 */
		public function getResizedResource() {
			$w = 0;
			$h = 0;
			$x = $this->owidth;
			$y = $this->oheight;
			
			if( $x > $y ) {
				$w = $this->nwidth;
				$h = $y * ( $this->nheight / $x );
			} else if( $x < $y ) {
				$w = $w * ( $this->nwidth / $y );
				$h = $this->nheight;
			} else {
				$w = $this->nwidth;
				$h = $this->nheight;
			}
			
			return imagecreatetruecolor( $w, $h );
		}
		
		/**
		 * Sets the image and path of the image to be resized.
		 * @param String $imagePath - The image path and file name.
		 */
		public function setImageAndPath( $imagePath ) {
			if( is_string( $imagePath ) ) {
				$this->image	 = $imagePath;
				$data 				 = getimagesize( $imagePath );
				$this->owidth	 = $data[0];
				$this->oheight = $data[1];
				$tmp 					 = explode( '/', $data['mime'] );
				$this->imgType = $tmp[1];
				$this->path 	 = dirname( $imagePath );
			}
		}
		
		/**
		 * Sets the resized image name.
		 * @param String $name - Only the resized file name (not the path).
		 */
		public function setResizedImageName( $name ) {
			if( preg_match( '/^[\w\.\-_]+$/', $name ) ) {
				$position			 = strrchr( $name, '.' );
				$this->newFile = preg_replace( "/$position/", '', $name );
			}
		}
		
		/**
		 * Set the new sizes.
		 * @param Integer[] $sizes - Set the new sizes to be used when resizing the image.
		 */
		public function setNewSizes( $sizes ) {
			if( is_array( $sizes ) && IMGResizer::areNumeric( $sizes ) ) {
				if( isset( $sizes['width'] ) && isset( $sizes['height'] ) ) {
					$this->nwidth = $sizes['width'];
					$this->nheight = $sizes['height'];
				} else {
					$this->nwidth = $sizes[0];
					$this->nheight = $sizes[1];
				}
			}
		}
		
		/**
		 * Checks whether or not the array contains only numbers or not.
		 * @param Mixed[] $array - The array to check.
		 * @return Boolean - True, if the array contains only numbers, false otherwise.
		 */
		public static function areNumeric( $array ) {
			$ret = true;
					
			if( ! is_array( $array ) ) {
				$ret &= is_numeric( $array );
			} else {
				foreach( $array as $element ) {
					if( is_array( $element ) ) {
						$ret &= areNumeric( $element );
					} else {
						$ret &= is_numeric( $element );
					}
					
					if( ! $ret )
						break;
				}
			}
					
			return $ret;
		}
		
		/**
		 * Wrapper arround imagecopyresampled.
		 * Uses the new image width (set with the class constructor or with setNewSizes( $sizes ) method) and the current image height and width.
		 * @param Resource $target - The target image resource.
		 * @param Resource $source - Original Image resource.
		 * @param Integer[] $coords - The coordinates to be used. The first 2 
		 * elements are the target coordinates and the last 2, the source image coordinates.
		 * @return Boolean | NULL - NULL if the $target or $source are not resources; True if
		 * the image was resampled or false if there was an error.
		 */
		public function resample( $target, $source, $coords = array() ) {
			if( is_resource( $target ) && is_resource( $source ) ) {
				$tx = 0;
				$ty = 0;
				$sx = 0;
				$sy = 0;
				
				if( ! empty( $coords ) && count( $coords ) == 4 ) {
					$tx = $coords[0];
					$ty = $coords[1];
					$sx = $coords[2];
					$sy = $coords[3];
				}
				
				return imagecopyresampled( $target, $source, $tx, $ty, $sx, $sy, $this->nwidth, $this->nheight, $this->owidth, $this->oheight );
			}
			
			return null;
		}
	}
?>

Ese es un ejemplo completo y funcionando :).
Lamento informarte skaparate que no es asi! (seguro te tengo re podrido) jaja ahora funciona con gif y jpg, pero tiene problemas cuando la imagenes es mas larga que ancha por ejemplo me tira Warnings cuando intento subir una imagen de 150px de ancho y 200px de largo la imagen la sube, pero no la redimenciona, la sube con su tamaño actual.
esto es lo que me tira:
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\3\catalogo\nuevo_producto.php on line 188
Linea 188: return imagecreatetruecolor( $w, $h );
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\wamp\www\3\catalogo\nuevo_producto.php on line 142
Linea 142 imagejpeg( $target, $fsave ); (la imagen que intente subir era jpg.)
Warning: imagedestroy() expects parameter 1 to be resource, boolean given in C:\wamp\www\3\catalogo\nuevo_producto.php on line 156
Linea 156: imagedestroy( $target );

Cuando subis una imagen mas ancha que larga ahi si funciona perfecto! :S por ejemplo subi una de 500 de ancho y 100 de largo y subio perfecto! y muchisimas gracias, mirando los otros temas veo que apartas un monton de tu conocimiento! felicitaciones, soy muy pocas las gente como vos que no mesquinan sus conocimientos y ayudan a los demas! muchas de nuevo, un abrazo!
ya solucione el problema, era solamente error en una variable, dejo toda la funcion para que se ubiquen mejor. Muchisimas gracias skaparate por todo!
public function getResizedResource() {
            $w = 0;
            $h = 0;
            $x = $this->owidth;
            $y = $this->oheight;
            
            if( $x > $y ) {
                $w = $this->nwidth;
                $h = $y * ( $this->nheight / $x );
            } else if( $x < $y ) {
                $w = $x * ( $this->nwidth / $y );
                $h = $this->nheight;
            } else {
                $w = $this->nwidth;
                $h = $this->nheight;
            }
            
            return imagecreatetruecolor( $w, $h );
        }
saludos y feliz año nuevo! :)
probando el script me di cuenta que aparte de achicar las imagenes tambien las corta... y las alarga un poco, para abajo o para la izquierda! :/ nose cual seria el problema ahi!
XD... perdón por no responder, pero estoy algo ocupado. Lo que te puedo recomendar, por el momento, es que utilices el código que aparece aquí. También es una clase y se utiliza de manera similar.

Cuando pueda reviso el código e intentaré arreglarlo. Te enviaré un Mensaje Privado cuando funcione nuevamente.

Ah!, feliz año nuevo para ti también.

Saludos.
no hay problema amigo! yo igual estaba intentando poner lo de transparencia a mi codigo de redimencionar.php pero se me complica por que nose que valor tiene algunas variable de la clase! jaja. Un saludos! :)
Que tal, logro solucionar el problema de la redimencion! (no creo que sea la solucion mas eficiente pero funciona) les dejo el codigo:
<?PHP
$a = 0;
$b = 0;
class IMGResizer {
        /**
         * The image file path.
         * @var String.
         */
        private $image = null;
        
        /**
         * Original image Width.
         * @var Integer.
         */
        private $owidth = 0;
        
        /**
         * Original image Height.
         * @var Integer.
         */
        private $oheight = 0;
        
        /**
         * Image file type (png, jpeg, jpg, gif, etc.). Currently only supports gif, png and jp(e)g.
         * @var String.
         */
        private $imgType = '';
        
        /**
         * Resize width.
         * @var Integer.
         */
        private $nwidth = 0;
        
        /**
         * Resize height.
         * @var Integer
         */
        private $nheight = 0;
        
        /**
         * Resized File name.
         * @var String.
         */
        private $newFile = '';
        
        /**
         * Image File base directory.
         * @var String.
         */
        private $path  = '';
        
        /**
         * A class to resize images.
         * @param String $imagePath - The image file name and path.
         * @param Integer[] $newSize - $newSize[0] is the width and $newSize[1] is the height.
         * @param String $resizedFileName - Optional; if not specified, the original filename will be used.
         */
        public function __construct( $imagePath, $newSize, $resizedFileName = '' ) {
            $this->image = $imagePath;
            $data = getimagesize( $imagePath );
            $this->owidth = $data[0];
            $this->oheight = $data[1];
            $tmp = explode( '/', $data['mime'] );
            $this->imgType = $tmp[1];
            $this->nwidth = $newSize[0];
            $this->nheight = $newSize[1];
            
            if( $resizedFileName )
                $this->newFile = $resizedFileName;
            else
                $this->newFile = basename( $imagePath );
            
            $this->path = dirname( $imagePath );
        }
        
        /**
         * @return String - Returns the new image file name.
         */
        public function resize() {
            $target = null;
            $source = null;
            $fsave = "$this->path/$this->newFile";
            
            switch( $this->imgType ) {
                case 'png':
				case 'PNG':
                    $source = imagecreatefrompng( $this->image );
                    $target = $this->getResizedResource();
                    imagealphablending( $target, false );
                    imagesavealpha( $target, true );
                    $transparent = imagecolorallocatealpha( $target, 255, 255, 255, 127 );
                    imagefilledrectangle( $target, 0, 0, $this->nwidth, $this->nheight, $transparent );
                    $this->resample( $target, $source );
                    imagepng( $target, $fsave );
                  
					break;
            
                case 'jpeg':
                case 'jpg':
				case 'JPEG':
				case 'JPG':
                    $target = $this->getResizedResource();
                    $source = imagecreatefromjpeg( $this->image );
                    $this->resample( $target, $source );
                    imagejpeg( $target, $fsave );
           
					break;
            
                case 'gif':
				case 'GIF':
                    $target = $this->getResizedResource();
                    $source = imagecreatefromgif( $this->image );
                    $this->resample( $target, $source );
                    imagegif( $target, $fsave );
             
					break;
            }
                
            if( $target !== null )
                imagedestroy( $target );
            
            if( $source !== null )
                imagedestroy( $source );
            
            chmod( $fsave, 0644 );
            return $this->newFile;
        }
        
        /**
         * Creates a true color image with the values of $newSize param.
         * @param Integer[] $origSize - Original Width and Height
         * @param Integer[] $newSize - New width and height.
         * @return Resource - Returns a resized image resource.
         */
        public function getResizedResource() {
            $w = 0;
            $h = 0;
            $x = $this->owidth;
            $y = $this->oheight;
            
            if( $x > $y ) {
                $w = $this->nwidth;
                $h = $y * ( $this->nheight / $x );
            } else if( $x < $y ) {
                $w = $x * ( $this->nwidth / $y );
                $h = $this->nheight;
            } else {
                $w = $this->nwidth;
                $h = $this->nheight;
            }
            $GLOBALS['a']= $w;
			$GLOBALS['b']= $h;
            return imagecreatetruecolor( $w, $h );
        }
        
        /**
         * Sets the image and path of the image to be resized.
         * @param String $imagePath - The image path and file name.
         */
        public function setImageAndPath( $imagePath ) {
            if( is_string( $imagePath ) ) {
                $this->image = $imagePath;
                $data = getimagesize( $imagePath );
                $this->owidth = $data[0];
                $this->oheight = $data[1];
                $tmp = explode( '/', $data['mime'] );
                $this->imgType = $tmp[1];
                $this->path = dirname( $imagePath );
            }
        }
        
        /**
         * Sets the resized image name.
         * @param String $name - Only the resized file name (not the path).
         */
        public function setResizedImageName( $name ) {
            if( preg_match( '/^[\w\.\-_]+$/', $name ) ) {
                $position = strrchr( $name, '.' );
                $this->newFile = preg_replace( "/$position/", '', $name );
            }
        }
        
        /**
         * Set the new sizes.
         * @param Integer[] $sizes - Set the new sizes to be used when resizing the image.
         */
        public function setNewSizes( $sizes ) {
            if( is_array( $sizes ) && IMGResizer::areNumeric( $sizes ) ) {
                if( isset( $sizes['width'] ) && isset( $sizes['height'] ) ) {
                    $this->nwidth = $sizes['width'];
                    $this->nheight = $sizes['height'];
                } else {
                    $this->nwidth = $sizes[0];
                    $this->nheight = $sizes[1];
                }
            }
        }
        
        /**
         * Checks whether or not the array contains only numbers or not.
         * @param Mixed[] $array - The array to check.
         * @return Boolean - True, if the array contains only numbers, false otherwise.
         */
        public static function areNumeric( $array ) {
            $ret = true;
                    
            if( ! is_array( $array ) ) {
                $ret &= is_numeric( $array );
            } else {
                foreach( $array as $element ) {
                    if( is_array( $element ) ) {
                        $ret &= areNumeric( $element );
                    } else {
                        $ret &= is_numeric( $element );
                    }
                    
                    if( ! $ret )
                        break;
                }
            }
                    
            return $ret;
        }
        
        /**
         * Wrapper arround imagecopyresampled.
         * Uses the new image width (set with the class constructor or with setNewSizes( $sizes ) method) and the current image height and width.
         * @param Resource $target - The target image resource.
         * @param Resource $source - Original Image resource.
         * @param Integer[] $coords - The coordinates to be used. The first 2 
         * elements are the target coordinates and the last 2, the source image coordinates.
         * @return Boolean | NULL - NULL if the $target or $source are not resources; True if
         * the image was resampled or false if there was an error.
         */
        public function resample( $target, $source, $coords = array() ) {
            if( is_resource( $target ) && is_resource( $source ) ) {
                $tx = 0;
                $ty = 0;
                $sx = 0;
                $sy = 0;
                
                if( ! empty( $coords ) && count( $coords ) == 4 ) {
                    $tx = $coords[0];
                    $ty = $coords[1];
                    $sx = $coords[2];
                    $sy = $coords[3];
                }
                
                return imagecopyresampled( $target, $source, $tx, $ty, $sx, $sy, $GLOBALS['a'], $GLOBALS['b'], $this->owidth, $this->oheight );
            }
             
            return null;
        }
    }
?>
Espero que les sirva abrazos y perdón por la demora! (grande jorge por pasarte por aca) :)
Ja! Los errores torpes que cometo XD. El código, siguiendo el estilo orientado a objetos, quedaría así:

class IMGResizer {
        /**
         * The image file path.
         * @var String.
         */
        private $image = null;
        
        /**
         * Original image Width.
         * @var Integer.
         */
        private $owidth = 0;
        
        /**
         * Original image Height.
         * @var Integer.
         */
        private $oheight = 0;
        
        /**
         * Image file type (png, jpeg, jpg, gif, etc.). Currently only supports gif, png and jp(e)g.
         * @var String.
         */
        private $imgType = '';
        
        /**
         * Resize width.
         * @var Integer.
         */
        private $nwidth = 0;
        
        /**
         * Resize height.
         * @var Integer
         */
        private $nheight = 0;
        
        /**
         * Resized File name.
         * @var String.
         */
        private $newFile = '';
        
        /**
         * Image File base directory.
         * @var String.
         */
        private $path  = '';
        
        /**
         * A class to resize images.
         * @param String $imagePath - The image file name and path.
         * @param Integer[] $newSize - $newSize[0] is the width and $newSize[1] is the height.
         * @param String $resizedFileName - Optional; if not specified, the original filename will be used.
         */
        public function __construct( $imagePath, $newSize, $resizedFileName = '' ) {
            $this->image = $imagePath;
            $data = getimagesize( $imagePath );
            $this->owidth = $data[0];
            $this->oheight = $data[1];
            $tmp = explode( '/', $data['mime'] );
            $this->imgType = $tmp[1];
            $this->nwidth = $newSize[0];
            $this->nheight = $newSize[1];
            
            if( $resizedFileName )
                $this->newFile = $resizedFileName;
            else
                $this->newFile = basename( $imagePath );
            
            $this->path = dirname( $imagePath );
        }
        
        /**
         * @return String - Returns the new image file name.
         */
        public function resize() {
            $target = null;
            $source = null;
            $fsave = "$this->path/$this->newFile";
            
            switch( $this->imgType ) {
                case 'png':
                case 'PNG':
                    $source = imagecreatefrompng( $this->image );
                    $target = $this->getResizedResource();
                    imagealphablending( $target, false );
                    imagesavealpha( $target, true );
                    $transparent = imagecolorallocatealpha( $target, 255, 255, 255, 127 );
                    imagefilledrectangle( $target, 0, 0, $this->nwidth, $this->nheight, $transparent );
                    $this->resample( $target, $source );
                    imagepng( $target, $fsave );
                  
                    break;
            
                case 'jpeg':
                case 'jpg':
                case 'JPEG':
                case 'JPG':
                    $target = $this->getResizedResource();
                    $source = imagecreatefromjpeg( $this->image );
                    $this->resample( $target, $source );
                    imagejpeg( $target, $fsave );
           
                    break;
            
                case 'gif':
                case 'GIF':
                    $target = $this->getResizedResource();
                    $source = imagecreatefromgif( $this->image );
                    $this->resample( $target, $source );
                    imagegif( $target, $fsave );
             
                    break;
            }
                
            if( $target !== null )
                imagedestroy( $target );
            
            if( $source !== null )
                imagedestroy( $source );
            
            chmod( $fsave, 0644 );
            return $this->newFile;
        }
        
        /**
         * Creates a true color image with the values of $newSize param.
         * @param Integer[] $origSize - Original Width and Height
         * @param Integer[] $newSize - New width and height.
         * @return Resource - Returns a resized image resource.
         */
        public function getResizedResource() {
            $w = 0;
            $h = 0;
            $x = $this->owidth;
            $y = $this->oheight;
            
            if( $x > $y ) {
                $w = $this->nwidth;
                $h = $y * ( $this->nheight / $x );
            } else if( $x < $y ) {
                $w = $x * ( $this->nwidth / $y );
                $h = $this->nheight;
            } else {
                $w = $this->nwidth;
                $h = $this->nheight;
            }

            $this->nwidth  = $w;
            $this->nheight = $h;

            return imagecreatetruecolor( $w, $h );
        }
        
        /**
         * Sets the image and path of the image to be resized.
         * @param String $imagePath - The image path and file name.
         */
        public function setImageAndPath( $imagePath ) {
            if( is_string( $imagePath ) ) {
                $this->image = $imagePath;
                $data = getimagesize( $imagePath );
                $this->owidth = $data[0];
                $this->oheight = $data[1];
                $tmp = explode( '/', $data['mime'] );
                $this->imgType = $tmp[1];
                $this->path = dirname( $imagePath );
            }
        }
        
        /**
         * Sets the resized image name.
         * @param String $name - Only the resized file name (not the path).
         */
        public function setResizedImageName( $name ) {
            if( preg_match( '/^[\w\.\-_]+$/', $name ) ) {
                $position = strrchr( $name, '.' );
                $this->newFile = preg_replace( "/$position/", '', $name );
            }
        }
        
        /**
         * Set the new sizes.
         * @param Integer[] $sizes - Set the new sizes to be used when resizing the image.
         */
        public function setNewSizes( $sizes ) {
            if( is_array( $sizes ) && IMGResizer::areNumeric( $sizes ) ) {
                if( isset( $sizes['width'] ) && isset( $sizes['height'] ) ) {
                    $this->nwidth = $sizes['width'];
                    $this->nheight = $sizes['height'];
                } else {
                    $this->nwidth = $sizes[0];
                    $this->nheight = $sizes[1];
                }
            }
        }
        
        /**
         * Checks whether or not the array contains only numbers or not.
         * @param Mixed[] $array - The array to check.
         * @return Boolean - True, if the array contains only numbers, false otherwise.
         */
        public static function areNumeric( $array ) {
            $ret = true;
                    
            if( ! is_array( $array ) ) {
                $ret &= is_numeric( $array );
            } else {
                foreach( $array as $element ) {
                    if( is_array( $element ) ) {
                        $ret &= areNumeric( $element );
                    } else {
                        $ret &= is_numeric( $element );
                    }
                    
                    if( ! $ret )
                        break;
                }
            }
                    
            return $ret;
        }
        
        /**
         * Wrapper arround imagecopyresampled.
         * Uses the new image width (set with the class constructor or with setNewSizes( $sizes ) method) and the current image height and width.
         * @param Resource $target - The target image resource.
         * @param Resource $source - Original Image resource.
         * @param Integer[] $coords - The coordinates to be used. The first 2 
         * elements are the target coordinates and the last 2, the source image coordinates.
         * @return Boolean | NULL - NULL if the $target or $source are not resources; True if
         * the image was resampled or false if there was an error.
         */
        public function resample( $target, $source, $coords = array() ) {
            if( is_resource( $target ) && is_resource( $source ) ) {
                $tx = 0;
                $ty = 0;
                $sx = 0;
                $sy = 0;
                
                if( ! empty( $coords ) && count( $coords ) == 4 ) {
                    $tx = $coords[0];
                    $ty = $coords[1];
                    $sx = $coords[2];
                    $sy = $coords[3];
                }
                
                // nwidth, nheight significan nuevo ancho (new width) y nueva altura (new height).
                // owidth, oheight significan ancho original (original width) y altura original (original width).
                return imagecopyresampled( $target, $source, $tx, $ty, $sx, $sy, $this->nwidth, $this->nheight, $this->owidth, $this->oheight );
            }
             
            return null;
        }
    }
?>

De esta forma se reasigna el valor del ancho y alto a nwidth y nheight para poder ser utilizados dentro de la clase.