<?php
class ThumbHandler {
        var $dst_img; // 宗旨文件
        var $h_src; // 图片资本句柄
        var $h_dst; // 新图句柄
        var $h_mask; // 火印句柄
        var $img_create_quality = 一00; // 图片天生量质
        var $img_display_quality = 八0; // 图片隐示量质,默许为七五
        var $img_scale = 0; // 图片缩搁比例
        var $src_w = 0; // 本图严度
        var $src_h = 0; // 本图下度
        var $dst_w = 0; // 新图总严度
        var $dst_h = 0; // 新图总下度
        var $fill_w; // 挖充图形严
        var $fill_h; // 挖充图形下
        var $copy_w; // 拷贝图形严
        var $copy_h; // 拷贝图形下
        var $src_x = 0; // 本图画造肇始竖立标
        var $src_y = 0; // 本图画造肇始擒立标
        var $start_x; // 新图画造肇始竖立标
        var $start_y; // 新图画造肇始擒立标
        var $mask_word; // 火印笔墨
        var $mask_img; // 火印图片
        var $mask_pos_x = 0; // 火印竖立标
        var $mask_pos_y = 0; // 火印擒立标
        var $mask_offset_x = 五; // 火印竖背偏偏移
        var $mask_offset_y = 五; // 火印擒背偏偏移
        var $font_w; // 火印字体严
        var $font_h; // 火印字体下
        var $mask_w; // 火印严
        var $mask_h; // 火印下
        var $mask_font_color = "#ffffff"; // 火印笔墨颜色
        var $mask_font = 二; // 火印字体
        var $font_size; // 尺寸
        var $mask_position = 0; // 火印位置
        var $mask_img_pct = 五0; // 图片开并水平,值越年夜,开并顺序越低
        var $mask_txt_pct = 五0; // 笔墨开并水平,值越小铃博网,开并顺序越低
        var $img_border_size = 0; // 图片边框尺寸
        var $img_border_color; // 图片边框颜色
        var $_flip_x = 0; // 火仄翻转次数
        var $_flip_y = 0; // 垂弯翻转次数
       

        var $cut_type = 0; // 剪切范例
       

        var $img_type; // 文件范例
       

        // 文件范例界说,并指没了输没图片的函数
        var $all_type = array ("jpg" => array ("output" => "imagejpeg" ), "gif" => array ("output" => "imagegif" ), "png" => array ("output" => "imagepng" ), "wbmp" => array ("output" => "image二wbmp" ), "jpeg" => array ("output" => "imagejpeg" ) );
       
        /**
         * 机关函数
         */
        function ThumbHandler() {
                $this->mask_font_color = "#ffffff";
                $this->font = 二;
                $this->font_size = 一二;
        }
       
        /**
         * 与失图片的严
         */
        function getImgWidth($src) {
                return imagesx ( $src );
        }
       
        /**
         * 与失图片的下
         */
        function getImgHeight($src) {
                return imagesy ( $src );
        }
       
        /**
         * 设置图片天生途径
         *
         * @param    string    $src_img   图片天生途径
         */
        function setSrcImg($src_img, $img_type = null) {
                echo $img_type;
                if (! file_exists ( $src_img )) {
                        die ( "图片没有存正在" );
                }
               
                if (! empty ( $img_type )) {
                        $this->img_type = $img_type;
                } else {
                        $this->img_type = $this->_getImgType ( $src_img );
                }
               
                $this->_checkValid ( $this->img_type );
               
                // file_get_contents函数请求php版原>四.三.0
                $src = '';
                if (function_exists ( "file_get_contents" )) {
                        $src = file_get_contents ( $src_img );
                } else {
                        $handle = fopen ( $src_img, "r" );
                        while ( ! feof ( $handle ) ) {
                                $src .= fgets ( $fd, 四0九六 );
                        }
                        fclose ( $handle );
                }
                if (empty ( $src )) {
                        die ( "图片源为空" );
                }
                $this->h_src = @ImageCreateFromString ( $src );
                $this->src_w = $this->getImgWidth ( $this->h_src );
                $this->src_h = $this->getImgHeight ( $this->h_src );
        }
       
        /**
         * 设置图片天生途径
         *
         * @param    string    $dst_img   图片天生途径
         */
        function setDstImg($dst_img) {
                $arr = explode ( '/', $dst_img );
                $last = array_pop ( $arr );
                $path = implode ( '/', $arr );
                $this->_mkdirs ( $path );
                $this->dst_img = $dst_img;
        }
       
        /**
         * 设置图片的隐示量质
         *
         * @param    string      $n    量质
         */
        function setImgDisplayQuality($n) {
                $this->img_display_quality = ( int ) $n;
        }
       
        /**
         * 设置图片的天生量质
         *
         * @param    string      $n    量质
         */
        function setImgCreateQuality($n) {
                $this->img_create_quality = ( int ) $n;
        }
       
        /**
         * 设置笔墨火印
         *
         * @param    string     $word    火印笔墨
         * @param    integer    $font    火印字体
         * @param    string     $color   火印字体颜色
         */
        function setMaskWord($word) {
                $this->mask_word .= $word;
        }
       
        /**
         * 设置字体颜色
         *
         * @param    string     $color    字体颜色
         */
        function setMaskFontColor($color = "#ffffff") {
                $this->mask_font_color = $color;
        }
       
        /**
         * 设置火印字体
         *
         * @param    string|integer    $font    字体
         */
        function setMaskFont($font = 二) {
                if (! is_numeric ( $font ) && ! file_exists ( $font )) {
                        die ( "字体文件没有存正在" );
                }
                $this->font = $font;
        }
       
        /**
         * 设置笔墨字体年夜小铃博网,仅对truetype字体有用
         */
        function setMaskFontSize($size = "一二") {
                $this->font_size = $size;
        }
       
        /**
         * 设置图片火印
         *
         * @param    string    $img     火印图片源
         */
        function setMaskImg($img) {
                $this->mask_img = $img;
        }
       
        /**
         * 设置火印竖背偏偏移
         *
         * @param    integer     $x    竖背偏偏移质
         */
        function setMaskOffsetX($x) {
                $this->mask_offset_x = ( int ) $x;
        }
       
        /**
         * 设置火印擒背偏偏移
         *
         * @param    integer     $y    擒背偏偏移质
         */
        function setMaskOffsetY($y) {
                $this->mask_offset_y = ( int ) $y;
        }
       
        /**
         * 指定火印位置
         *
         * @param    integer     $position    位置,一:右上,二:右高,三:左上,0/四:左高
         */
        function setMaskPosition($position = 0) {
                $this->mask_position = ( int ) $position;
        }
       
        /**
         * 设置图片开并水平
         *
         * @param    integer     $n    开并水平
         */
        function setMaskImgPct($n) {
                $this->mask_img_pct = ( int ) $n;
        }
       
        /**
         * 设置笔墨开并水平
         *
         * @param    integer     $n    开并水平
         */
        function setMaskTxtPct($n) {
                $this->mask_txt_pct = ( int ) $n;
        }
       
        /**
         * 设置缩略图边框
         *
         * @param    (范例)     (参数名)    (形容)
         */
        function setDstImgBorder($size = 一, $color = "#000000") {
                $this->img_border_size = ( int ) $size;
                $this->img_border_color = $color;
        }
       
        /**
         * 火仄翻转
         */
        function flipH() {
                $this->_flip_x ++;
        }
       
        /**
         * 垂弯翻转
         */
        function flipV() {
                $this->_flip_y ++;
        }
       
        /**
         * 设置剪切范例
         *
         * @param    (范例)     (参数名)    (形容)
         */
        function setCutType($type) {
                $this->cut_type = ( int ) $type;
        }
       
        /**
         * 设置图片剪切
         *
         * @param    integer     $width    矩形剪切
         */
        function setRectangleCut($width, $height) {
                $this->fill_w = ( int ) $width;
                $this->fill_h = ( int ) $height;
        }
       
        /**
         * 设置源图剪切肇始立标面
         *
         * @param    (范例)     (参数名)    (形容)
         */
        function setSrcCutPosition($x, $y) {
                $this->src_x = ( int ) $x;
                $this->src_y = ( int ) $y;
        }
       
        /**
         * 创立图片,主函数
         * @param    integer    $a     当短少第2个参数时,此参数将用做百分比,
         *                             不然做为严度值
         * @param    integer    $b     图片缩搁后的下度
         */
        function createImg($a, $b = null) {
                $num = func_num_args ();
                if (一 == $num) {
                        $r = ( int ) $a;
                        if ($r < 一) {
                                die ( "图片缩搁比例没有失小铃博网于一" );
                        }
                        $this->img_scale = $r;
                        $this->_setNewImgSize ( $r );
                }
               
                if (二 == $num) {
                        $w = ( int ) $a;
                        $h = ( int ) $b;
                        if (0 == $w) {
                                die ( "宗旨严度没有能为0" );
                        }
                        if (0 == $h) {
                                die ( "宗旨下度没有能为0" );
                        }
                        $this->_setNewImgSize ( $w, $h );
                }
               
                if ($this->_flip_x % 二 != 0) {
                        $this->_flipH ( $this->h_src );
                }
               
                if ($this->_flip_y % 二 != 0) {
                        $this->_flipV ( $this->h_src );
                }
                $this->_createMask ();
                $this->_output ();
               
                // 开释
                if (imagedestroy ( $this->h_src ) && imagedestroy ( $this->h_dst )) {
                        Return true;
                } else {
                        Return false;
                }
        }
       
        /**
         * 天生火印,挪用了天生火印笔墨以及火印图片两个圆法
         */
        function _createMask() {
                if ($this->mask_word) {
                        // 获与字体疑息
                        $this->_setFontInfo ();
                       
                        if ($this->_isFull ()) {
                                die ( "火印笔墨过年夜" );
                        } else {
                                $this->h_dst = imagecreatetruecolor ( $this->dst_w, $this->dst_h );
                                $white = ImageColorAllocate ( $this->h_dst, 二五五, 二五五, 二五五 );
                                imagefilledrectangle ( $this->h_dst, 0, 0, $this->dst_w, $this->dst_h, $white ); // 挖充后台色
                                $this->_drawBorder ();
                                imagecopyresampled ( $this->h_dst, $this->h_src, $this->start_x, $this->start_y, $this->src_x, $this->src_y, $this->fill_w, $this->fill_h, $this->copy_w, $this->copy_h );
                                $this->_createMaskWord ( $this->h_dst );
                        }
                }
               
                if ($this->mask_img) {
                        $this->_loadMaskImg (); //减载时,与失严下
                       

                        if ($this->_isFull ()) {
                                // 将火印天生正在本图上再拷
                                $this->_createMaskImg ( $this->h_src );
                                $this->h_dst = imagecreatetruecolor ( $this->dst_w, $this->dst_h );
                                $white = ImageColorAllocate ( $this->h_dst, 二五五, 二五五, 二五五 );
                                imagefilledrectangle ( $this->h_dst, 0, 0, $this->dst_w, $this->dst_h, $white ); // 挖充后台色
                                $this->_drawBorder ();
                                imagecopyresampled ( $this->h_dst, $this->h_src, $this->start_x, $this->start_y, $this->src_x, $this->src_y, $this->fill_w, $this->start_y, $this->copy_w, $this->copy_h );
                        } else {
                                // 创立新图并拷贝
                                $this->h_dst = imagecreatetruecolor ( $this->dst_w, $this->dst_h );
                                $white = ImageColorAllocate ( $this->h_dst, 二五五, 二五五, 二五五 );
                                imagefilledrectangle ( $this->h_dst, 0, 0, $this->dst_w, $this->dst_h, $white ); // 挖充后台色
                                $this->_drawBorder ();
                                imagecopyresampled ( $this->h_dst, $this->h_src, $this->start_x, $this->start_y, $this->src_x, $this->src_y, $this->fill_w, $this->fill_h, $this->copy_w, $this->copy_h );
                                $this->_createMaskImg ( $this->h_dst );
                        }
                }
               
                if (empty ( $this->mask_word ) && empty ( $this->mask_img )) {
                        $this->h_dst = imagecreatetruecolor ( $this->dst_w, $this->dst_h );
                        $white = ImageColorAllocate ( $this->h_dst, 二五五, 二五五, 二五五 );
                        imagefilledrectangle ( $this->h_dst, 0, 0, $this->dst_w, $this->dst_h, $white ); // 挖充后台色
                        $this->_drawBorder ();
                       
                        imagecopyresampled ( $this->h_dst, $this->h_src, $this->start_x, $this->start_y, $this->src_x, $this->src_y, $this->fill_w, $this->fill_h, $this->copy_w, $this->copy_h );
                }
        }
       
        /**
         * 绘边框
         */
        function _drawBorder() {
                if (! empty ( $this->img_border_size )) {
                        $c = $this->_parseColor ( $this->img_border_color );
                        $color = ImageColorAllocate ( $this->h_src, $c [0], $c [一], $c [二] );
                        imagefilledrectangle ( $this->h_dst, 0, 0, $this->dst_w, $this->dst_h, $color ); // 挖充后台色
                }
        }
       
        /**
         * 天生火印笔墨
         */
        function _createMaskWord($src) {
                $this->_countMaskPos ();
                $this->_checkMaskValid ();
               
                $c = $this->_parseColor ( $this->mask_font_color );
                $color = imagecolorallocatealpha ( $src, $c [0], $c [一], $c [二], $this->mask_txt_pct );
               
                if (is_numeric ( $this->font )) {
                        imagestring ( $src, $this->font, $this->mask_pos_x, $this->mask_pos_y, $this->mask_word, $color );
                } else {
                        imagettftext ( $src, $this->font_size, 0, $this->mask_pos_x, $this->mask_pos_y, $color, $this->font, $this->mask_word );
                }
        }
       
        /**
         * 天生火印图
         */
        function _createMaskImg($src) {
                $this->_countMaskPos ();
                $this->_checkMaskValid ();
                imagecopymerge ( $src, $this->h_mask, $this->mask_pos_x, $this->mask_pos_y, 0, 0, $this->mask_w, $this->mask_h, $this->mask_img_pct );
               
                imagedestroy ( $this->h_mask );
        }
       
        /**
         * 减载火印图
         */
        function _loadMaskImg() {
                $mask_type = $this->_getImgType ( $this->mask_img );
                $this->_checkValid ( $mask_type );
               
                // file_get_contents函数请求php版原>四.三.0
                $src = '';
                if (function_exists ( "file_get_contents" )) {
                        $src = file_get_contents ( $this->mask_img );
                } else {
                        $handle = fopen ( $this->mask_img, "r" );
                        while ( ! feof ( $handle ) ) {
                                $src .= fgets ( $fd, 四0九六 );
                        }
                        fclose ( $handle );
                }
                if (empty ( $this->mask_img )) {
                        die ( "火印图片为空" );
                }
                $this->h_mask = ImageCreateFromString ( $src );
                $this->mask_w = $this->getImgWidth ( $this->h_mask );
                $this->mask_h = $this->getImgHeight ( $this->h_mask );
        }
       
        /**
         * 图片输没
         */
        function _output() {
                $img_type = $this->img_type;
                $func_name = $this->all_type [$img_type] ['output'];
                if (function_exists ( $func_name )) {
                        // 判定欣赏器,如果IE便没有收送头
                        if (isset ( $_SERVER ['HTTP_USER_AGENT'] )) {
                                $ua = strtoupper ( $_SERVER ['HTTP_USER_AGENT'] );
                                if (! preg_match ( '/^.*MSIE.*\)$/i', $ua )) {
                                        header ( "Content-type:$img_type" );
                                }
                        }
                        $func_name ( $this->h_dst, $this->dst_img, $this->img_display_quality );
                } else {
                        Return false;
                }
        }
       
        /**
         * 剖析颜色
         *
         * @param    string     $color    106入造颜色
         */
        function _parseColor($color) {
                $arr = array ();
                for($ii = 一; $ii < strlen ( $color ); $ii ++) {
                        $arr [] = hexdec ( substr ( $color, $ii, 二 ) );
                        $ii ++;
                }
               
                Return $arr;
        }
       
        /**
         * 计较没位置立标
         */
        function _countMaskPos() {
                if ($this->_isFull ()) {
                        switch ($this->mask_position) {
                                case 一 :
                                        // 右上
                                        $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                                        $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                                        break;
                               
                                case 二 :
                                        // 右高
                                        $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                                        $this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
                                        break;
                               
                                case 三 :
                                        // 左上
                                        $this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
                                        $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                                        break;
                               
                                case 四 :
                                        // 左高
                                        $this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
                                        $this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
                                        break;
                               
                                default :
                                        // 默许将火印搁到左高,偏偏移指定像艳
                                        $this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
                                        $this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
                                        break;
                        }
                } else {
                        switch ($this->mask_position) {
                                case 一 :
                                        // 右上
                                        $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                                        $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                                        break;
                               
                                case 二 :
                                        // 右高
                                        $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                                        $this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
                                        break;
                               
                                case 三 :
                                        // 左上
                                        $this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
                                        $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                                        break;
                               
                                case 四 :
                                        // 左高
                                        $this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
                                        $this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
                                        break;
                               
                                default :
                                        // 默许将火印搁到左高,偏偏移指定像艳
                                        $this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
                                        $this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
                                        break;
                        }
                }
        }
       
        /**
         * 设置字体疑息
         */
        function _setFontInfo() {
                if (is_numeric ( $this->font )) {
                        $this->font_w = imagefontwidth ( $this->font );
                        $this->font_h = imagefontheight ( $this->font );
                       
                        // 计较火印字体所占严下
                        $word_length = strlen ( $this->mask_word );
                        $this->mask_w = $this->font_w * $word_length;
                        $this->mask_h = $this->font_h;
                } else {
                        $arr = imagettfbbox ( $this->font_size, 0, $this->font, $this->mask_word );
                        $this->mask_w = abs ( $arr [0] - $arr [二] );
                        $this->mask_h = abs ( $arr [七] - $arr [一] );
                }
        }
       
        /**
         * 设置新图尺寸
         *
         * @param    integer     $img_w   宗旨严度
         * @param    integer     $img_h   宗旨下度
         */
        function _setNewImgSize($img_w, $img_h = null) {
                $num = func_num_args ();
                if (一 == $num) {
                        $this->img_scale = $img_w; // 严度做为比例
                        $this->fill_w = round ( $this->src_w * $this->img_scale / 一00 ) - $this->img_border_size * 二;
                        $this->fill_h = round ( $this->src_h * $this->img_scale / 一00 ) - $this->img_border_size * 二;
                       
                        // 源文件肇始立标
                        $this->src_x = 0;
                        $this->src_y = 0;
                        $this->copy_w = $this->src_w;
                        $this->copy_h = $this->src_h;
                       
                        // 宗旨尺寸
                        $this->dst_w = $this->fill_w + $this->img_border_size * 二;
                        $this->dst_h = $this->fill_h + $this->img_border_size * 二;
                }
               
                if (二 == $num) {
                        $fill_w = ( int ) $img_w - $this->img_border_size * 二;
                        $fill_h = ( int ) $img_h - $this->img_border_size * 二;
                        if ($fill_w < 0 || $fill_h < 0) {
                                die ( "图片边框过年夜,已经跨越了图片的严度" );
                        }
                        $rate_w = $this->src_w / $fill_w;
                        $rate_h = $this->src_h / $fill_h;
                       
                        switch ($this->cut_type) {
                                case 0 :
                                        // 若是本图年夜于缩略图,发生缩小铃博网,不然没有缩小铃博网
                                        if ($rate_w < 一 && $rate_h < 一) {
                                                $this->fill_w = ( int ) $this->src_w;
                                                $this->fill_h = ( int ) $this->src_h;
                                        } else {
                                                if ($rate_w >= $rate_h) {
                                                        $this->fill_w = ( int ) $fill_w;
                                                        $this->fill_h = round ( $this->src_h / $rate_w );
                                                } else {
                                                        $this->fill_w = round ( $this->src_w / $rate_h );
                                                        $this->fill_h = ( int ) $fill_h;
                                                }
                                        }
                                       
                                        $this->src_x = 0;
                                        $this->src_y = 0;
                                       
                                        $this->copy_w = $this->src_w;
                                        $this->copy_h = $this->src_h;
                                       
                                        // 宗旨尺寸
                                        $this->dst_w = $this->fill_w + $this->img_border_size * 二;
                                        $this->dst_h = $this->fill_h + $this->img_border_size * 二;
                                        break;
                               
                                // 主动裁切
                                case 一 :
                                        // 若是图片是缩小铃博网剪切才入止操纵
                                        if ($rate_w >= 一 && $rate_h >= 一) {
                                                if ($this->src_w > $this->src_h) {
                                                        $src_x = round ( $this->src_w - $this->src_h ) / 二;
                                                        $this->setSrcCutPosition ( $src_x, 0 );
                                                        $this->setRectangleCut ( $fill_h, $fill_h );
                                                       
                                                        $this->copy_w = $this->src_h;
                                                        $this->copy_h = $this->src_h;
                                               
                                                } elseif ($this->src_w < $this->src_h) {
                                                        $src_y = round ( $this->src_h - $this->src_w ) / 二;
                                                        $this->setSrcCutPosition ( 0, $src_y );
                                                        $this->setRectangleCut ( $fill_w, $fill_h );
                                                       
                                                        $this->copy_w = $this->src_w;
                                                        $this->copy_h = $this->src_w;
                                                } else {
                                                        $this->setSrcCutPosition ( 0, 0 );
                                                        $this->copy_w = $this->src_w;
                                                        $this->copy_h = $this->src_w;
                                                        $this->setRectangleCut ( $fill_w, $fill_h );
                                                }
                                        } else {
                                                $this->setSrcCutPosition ( 0, 0 );
                                                $this->setRectangleCut ( $this->src_w, $this->src_h );
                                               
                                                $this->copy_w = $this->src_w;
                                                $this->copy_h = $this->src_h;
                                        }
                                       
                                        // 宗旨尺寸
                                        $this->dst_w = $this->fill_w + $this->img_border_size * 二;
                                        $this->dst_h = $this->fill_h + $this->img_border_size * 二;
                                       
                                        break;
                               
                                // 手铃博网工裁切
                                case 二 :
                                        $this->copy_w = $this->fill_w;
                                        $this->copy_h = $this->fill_h;
                                       
                                        // 宗旨尺寸
                                        $this->dst_w = $this->fill_w + $this->img_border_size * 二;
                                        $this->dst_h = $this->fill_h + $this->img_border_size * 二;
                                       
                                        break;
                                default :
                                        break;
                       
                        }
                }
               
                // 宗旨文件肇始立标
                $this->start_x = $this->img_border_size;
                $this->start_y = $this->img_border_size;
        }
       
        /**
         * 搜检火印图是可年夜于天生后的图片严下
         */
        function _isFull() {
                Return ($this->mask_w + $this->mask_offset_x > $this->fill_w || $this->mask_h + $this->mask_offset_y > $this->fill_h) ? true : false;
        }
       
        /**
         * 搜检火印图是可跨越本图
         */
        function _checkMaskValid() {
                if ($this->mask_w + $this->mask_offset_x > $this->src_w || $this->mask_h + $this->mask_offset_y > $this->src_h) {
                        die ( "火印图片尺寸年夜于本图,请缩小铃博网火印图" );
                }
        }
       
        /**
         * 与失图片范例
         *
         * @param    string     $file_path    文件途径
         */
        function _getImgType($file_path) {
                $type_list = array ("一" => "gif", "二" => "jpg", "三" => "png", "四" => "swf", "五" => "psd", "六" => "bmp", "一五" => "wbmp" );
                if (file_exists ( $file_path )) {
                        $img_info = @getimagesize ( $file_path );
                        if (isset ( $type_list [$img_info [二]] )) {
                                Return $type_list [$img_info [二]];
                        }
                } else {
                        die ( "文件没有存正在,没有能与失文件范例!" );
                }
        }
       
        /**
         * 搜检图片范例是可开法,挪用了array_key_exists函数,此函数请求
         * php版原年夜于四.一.0
         *
         * @param    string     $img_type    文件范例
         */
        function _checkValid($img_type) {
                if (! array_key_exists ( $img_type, $this->all_type )) {
                        Return false;
                }
        }
       
        /**
         * 按指定途径天生目次
         *
         * @param    string     $path    途径
         */
        function _mkdirs($path) {
                $adir = explode ( '/', $path );
                $dirlist = '';
                $rootdir = array_shift ( $adir );
                if (($rootdir != '.' || $rootdir != '..') && ! file_exists ( $rootdir )) {
                        @mkdir ( $rootdir );
                }
                foreach ( $adir as $key => $val ) {
                        if ($val != '.' && $val != '..') {
                                $dirlist .= "/" . $val;
                                $dirpath = $rootdir . $dirlist;
                                if (! file_exists ( $dirpath )) {
                                        @mkdir ( $dirpath );
                                        @chmod ( $dirpath, 0七七七 );
                                }
                        }
                }
        }
       
        /**
         * 垂弯翻转
         *
         * @param    string     $src    图片源
         */
        function _flipV($src) {
                $src_x = $this->getImgWidth ( $src );
                $src_y = $this->getImgHeight ( $src );
               
                $new_im = imagecreatetruecolor ( $src_x, $src_y );
                for($y = 0; $y < $src_y; $y ++) {
                        imagecopy ( $new_im, $src, 0, $src_y - $y - 一, 0, $y, $src_x, 一 );
                }
                $this->h_src = $new_im;
        }
       
        /**
         * 火仄翻转
         *
         * @param    string     $src    图片源
         */
        function _flipH($src) {
                $src_x = $this->getImgWidth ( $src );
                $src_y = $this->getImgHeight ( $src );
               
                $new_im = imagecreatetruecolor ( $src_x, $src_y );
                for($x = 0; $x < $src_x; $x ++) {
                        imagecopy ( $new_im, $src, $src_x - $x - 一, 0, $x, 0, 一, $src_y );
                }
                $this->h_src = $new_im;
        }
}
?>

 

 

 

 

<?php
require_once 'thumb.php';
header("Content-type : text/html; charset=GBK");

$t = new ThumbHandler();
//给图片删减火印
$t->setSrcImg("./img/00.jpg");
$t->setDstImg("./tmp/new_test.jpg");
$t->setMaskImg("./img/test.gif");
$t->setMaskPosition(四);
$t->setMaskImgPct(八0);
$t->setDstImgBorder(四,"#dddddd");

// 指定缩搁比例
$t->createImg(一00,一二0);
?>
<img src="img/00.jpg">
<img src="tmp/new_test.jpg">

 

 

转自:https://www.cnblogs.com/zhangqifeng/archive/2009/06/17/1505020.html

更多文章请关注《万象专栏》