public function thumbnail($width, $height, $cropOrPad = false, $padColor = null)
    {
        // get the aspect ratio
        $currentSize = $this->getSize();
        $ar = round($currentSize['width'] / $currentSize['height'], 3);
        $nar = round($width / $height, 3);

        $newWidth = $width;
        $newHeight = $height;
        if ($ar >= 1) {
            if ($nar > $ar) {
                $newHeight = $width / $ar;
            } else {
                $newWidth = $height * $ar;
            }
        } else {
            if ($nar > $ar) {
                $newHeight = $width / $ar;
            } else {
                $newWidth = $height * $ar;
            }
        }
        $this->resize($newWidth, $newHeight);

        // crop
        if ($cropOrPad == self::CROP) {
            $this->crop($width, $height);
        }

        // pad
        if ($cropOrPad == self::PAD) {
            $padColor = !empty($padColor) ? $padColor : 'ffffff';
            $image = ImageLoader::create($width, $height, $padColor);

            // re-calculate the size based on aspect ratio
            if ($width < $height) {
                $newWidth = $width;
                $newHeight = round($width / $ar, 0);
            } else {
                $newWidth = round($height / $ar, 0);
                $newHeight = $height;
            }

            // center the padded image
            $offsetX = ($width - $newWidth) / 2;
            $offsetY = ($height - $newHeight) / 2;

            // resize the current image
            $this->resize($newWidth, $newHeight);

            $image->paste($this, $offsetX, $offsetY);
            $this->image = $image->getInstance();
            unset($image);
        }

        return $this;
    }