php 上传图片可按比例生成缩略图

        如下是一个功能比较齐全的php图片上传类,
        主要功能:
            1.可按比例生成缩略图
            2.可设置水印的位置
            3.可生成一个可能失真的略缩图.
        下面是其中的一个函数,如若查看或是使用可下载该文件类.
function config( $ImgArray ) {
        $this->SourcePicFile = $ImgArray ['SourceFile'];
        $this->FilePath = isset( $ImgArray ['NewFilePath'] ) ? $ImgArray ['NewFilePath'] : '';
        $this->f0 = 'upload/';
        $this->f1 = date( 'Y' ) . "-" . date( 'm' ) . "/";
        $this->f2 = date( 'd' ) . "/";
        $this->NewFileName = $ImgArray ['NewFileName'];
        if ($this->FilePath != '') {
                $this->AimPicFile = $this->FilePath . $this->f1 . $this->f2 . $this->NewFileName;
        } else {
                $this->AimPicFile = $this->f0 . $this->f1 . $this->f2 . $this->NewFileName;
        }
        $this->Width = isset( $ImgArray ['Width'] ) ? $ImgArray ['Width'] : '200';
        $this->Height = isset( $ImgArray ['Height'] ) ? $ImgArray ['Height'] : '150';
        $this->Background = isset( $ImgArray ['Background'] ) ? $ImgArray ['Background'] : '#ffffff';
        $this->PaiBorderColor = isset( $ImgArray ['PaiBorderColor'] ) ? $ImgArray ['PaiBorderColor'] : '#ffffff';
        //水印类配置
        $this->MarkText = isset( $ImgArray ['Mark'] ['MarkText'] ) ? $ImgArray ['Mark'] ['MarkText'] : '水印';//水印文字
        $this->MarkTextSize = isset( $ImgArray ['Mark'] ['MarkTextSize'] ) ? $ImgArray ['Mark'] ['MarkTextSize'] : 20;//文字大小
        $this->MarkColor = isset( $ImgArray ['Mark'] ['MarkColor'] ) ? $ImgArray ['Mark'] ['MarkColor'] : '#ffffff';//文字颜色
        $this->MarkBack = isset( $ImgArray ['Mark'] ['MarkBack'] ) ? $ImgArray ['Mark'] ['MarkBack'] : '#ffffff';//背景颜色
        $this->MarkAlpha = isset( $ImgArray ['Mark'] ['MarkAlpha'] ) ? $ImgArray ['Mark'] ['MarkAlpha'] : 0;//背景透明度
        $this->MarkTTF = isset( $ImgArray ['Mark'] ['MarkTTF'] ) ? $ImgArray ['Mark'] ['MarkTTF'] : './fonts/msyh.ttf';//水印字体
        $this->MarkImgFile = isset( $ImgArray ['Mark'] ['MarkImgFile'] ) ? $ImgArray ['Mark'] ['MarkImgFile'] : '';//图片水印路径
        $this->MarkLocation = isset( $ImgArray ['Mark'] ['MarkLocation'] ) ? $ImgArray ['Mark'] ['MarkLocation'] : 6;//水印位置
        //验证
        $this->ImgDetails();
        }
主要的配置和使用方法如下
/*
//配置数组
$ImgArray = array (
        'SourcePicFile' => $dir . 'a2.jpg', //来源图像
        'AimPicFile' => $dir . 'a2.jpg.jpg', //操作后图像
        'Width' => 200, //略缩图宽
        'Height' => 200, //略缩图高
        'Background' => '#cccfff', //背景空白处的填充颜色
        'PaiBorderColor' => '#000000', //略缩图边框颜色,为空则无边框
        'Mark' => array (//水印用的配置
                'MarkText' => "水印文字", //水印文字
                'MarkTextSize' => 20, //文字大小
                'MarkColor' => '#000000', //文字颜色
                'MarkBack' => '#ffffff', //背景颜色
                'MarkAlpha' => 50, //背景透明度
                'MarkTTF' => 'd:/web7/www/code/thumb/font/汉仪柏青体简.ttf', //字体文件
                'MarkImgFile' => 'mark/mark.png', //图片水印地址
                'MarkLocation' => 0
        )//水印位置
 ); //1=左上 2=左中 3=左下 4=中上 5=中中 6=中下 7=右上 8=右中 9=右下 0=随机

 //使用方法
    $p = new ImgUpload ( $ImgArray );
                直接生成一个可能失真的略缩图
                必须配置 SourcePicFile / AimPicFile / Width / Height
                可选配置 PaiBorderColor
    //$p->Thumb();
                生成一个不会失真的略缩图
                必须配置 SourcePicFile / AimPicFile / Width / Height
                可选配置 Background / PaiBorderColor
                附加参数
                0 = 保证显示全图,不足宽高之处以Background填充
                1 = 保证填充宽高,图片多余部分丢弃(裁剪原图中间部分)
    //$p->ThumbPro(0);
                生成一个文字水印,比较啰嗦
                主要是生成一个带背景的文字框,需要iconv函数支持,可以随即定义位置。
                必须配置 SourcePicFile / AimPicFile / mark{MarkText/MarkTextSize/MarkColor/MarkTTF/MarkLocation}
                可选:MarkBack / MarkAlpha
    //$p->MarkText();
                图片水印必须配置 SourcePicFile / AimPicFile / mark{MarkImgFile/MarkLocation}
    $p->MarkImg ();      
*/