Mam problem ze zmniejszaniem zdjęć w PHP

Mam następujący kod:
class Image { const JPG = 'jpg'; const JPEG = 'jpeg'; const GIF = 'gif'; const PNG = 'png'; private $handle; private $width; private $height; private $imageType; function __construct($fileName = '') { if ($fileName) { $this->open($fileName); } } function __destruct() { if ($this->handle) { $this->close(); } } public function setImageType($imageType) { $this->imageType = $imageType; return $this; } public function getImageType() { return $this->imageType; } public function create($imageType, $width, $height) { $this->imageType = $imageType; $this->handle = imagecreatetruecolor($width, $height); $this->width = $width; $this->height = $height; return $this; } /** * Otwarcie obrazu * @param string $fileName Sciezka/nazwa pliku */ public function open($fileName) { { throw new Exception("$fileName does not exist"); } switch ($this->imageType) { case 'jpeg': case 'jpg': $this->handle = @imagecreatefromjpeg($fileName); break; case 'gif': $this->handle = @imagecreatefromgif($fileName); break; case 'png': $this->handle = @imagecreatefrompng($fileName); break; default: throw new Exception('Unsupported image format'); } } public function getHandle() { return $this->handle; } /** * Zamyka uchwyt i konczy prace z obrazem */ public function close() { @imagedestroy($this->handle); } /** * Zwraca szerokosc obrazu * @return int */ public function getWidth() { return $this->width; } /** * Zwraca wysokosc obrazu * @return int */ public function getHeight() { return $this->height; } /** * Zmiara rozmiaru obrazu do wartosci podanych w parametrach * @param int $width * @param int $height */ public function resize($width, $height) { $image = @imagecreatetruecolor($width, $height); //$this->handle = imagealphablending ($image, true); @imagecopyresampled($image, $this->handle, 0, 0, 0, 0, $width, $height, $this->width, $this->height); $this->handle = $image; $this->width = $width; $this->height = $height; } /** * Konwersja do systemu szestnastkowego * @param int $red * @param int $green * @param int $blue * @return string */ public function rgb2hex($red, $green, $blue) { } /** * Konwersja liczby szestnastkowej okreslajacej kolor, do tablicy liczb RGB * @param string $hex np. #ccc lub #f8f8f8 * @return array */ public function hex2rgb($hex) { if ($hex{0} == '#') { } { } { } else { return false; } } /** * Metoda generuje miniature o podanych rozmiarach * @param int $width Szerokosc w px * @param int $height Wysokosc w px * @param strig $color Kolor tla dla miniatury */ public function thumbnail($width, $height, $color = '#FFF') { // jezeli wysokosc jest MNIEJSZA niz szerokosc // obraz poziomy if ($this->height < $this->width) { $ratio = $this->getHeight() / $this->getWidth(); $cHeight = $width * $ratio; $this->resize($width, $cHeight); } // obraz pionowy else { $ratio = $this->getWidth() / $this->getHeight(); $cWidth = $height * $ratio; $this->resize($cWidth, $height); } list($red, $green, $blue) = $this->hex2rgb($color); $output = imagecreatetruecolor($width, $height); $color = imagecolorallocate($output, $red, $green, $blue); imagefill($output, 0, 0, $color); $this->handle = $output; } /** * Zapis obrazu do pliku * @param $fileName Nazwa (sciezka) pliku */ public function save($fileName) { switch ($this->imageType) { case 'jpg': case 'jpeg': @imagejpeg($this->handle, $fileName, 80); break; case 'gif': @imagegif($this->handle, $fileName); break; case 'png': @imagepng($this->handle, $fileName); break; } } } $image = new Image("pliki/" . "" . $f1a); $image->thumbnail(160, 240, '#FFFFFF'); $image->save("pliki/" . "mini222_" . $f1a); // miniatura $image->close();
Zdjęcie źródłowe wygląda następująco:

skrypt obrabia mi fotkę do czegoś takiego:

a Chciałbym żeby to wyglądało następująco:

Czyli całe zdjęcie, sformatowane tak ażeby się mieściło proporcjonalnie...

Generalnie mam różnego rodzaju fotki i chciałbym żeby miniaturka tak operowała tymi białymi paskami ażeby zawsze całe fotki były widoczne...
Macie pomysł co mam źle w moim skrypcie?
North