添加到QQ书签 | 设为首页 | 加入收藏 | 繁體中文 | 网站地图
 | 网站首页 | QQ空间大图 | QQ空间FLASH模块 | QQ闪字表情 | QQ系列 | QQ下载 | 博客系列 | 完美图片 | 游戏秘籍 | 基础教程 | 
 | 精美字体 | 精品娃娃 | 个性签名 | 动感图片 | 制作素材 | 边框线条 | 视频·搞笑图片 | 基础知识 | 网页设计 | 
推 荐 阅 读
  • 没有推荐文章
  • 阅 读 排 行
    ·网页鼠标特效:在鼠标后面…
    ·在文本框默认自动输入当前…
    ·网页图片特效:图片动态水…
    ·网页鼠标特效:黑暗火光
    ·CSS基础知识:样式表CSS中…
    ·PHP源代码:图片加入文字…
    ·PHP源代码:Email图片生成
    ·CSS解决图片下有空隙
    ·纯CSS制作的网页中的ligh…
    ·网页图片鼠标动作特效:图…
    ·在线处理示意等待的AJAX动…
    ·11个图片上传加水印PHP源…
    ·CSS实现排版段落前面空两…
    ·网页时间特效:漂亮的脚本…
    ·PHP源代码:在图片上添加…
    ·DIV和CSS排版中制作细线条…
    ·CSS样式表参考:常用的CS…
    ·CSS优化:网页技术CSS的f…
    ·网页相册图片特效:矩阵鼠…
    ·PHP创建文字图片源码
     
    11个图片上传加水印PHP源代码 【字体:
     您现在的位置: QQ宝页站 >> 网页设计 >> PHP >> 正文 添加到百度搜藏 添加到QQ书签
     作者:佚名    文章来源:不详    点击数:    更新时间:2008-7-25  

    <?

     /**
         * 生成水印,调用了生成水印文字和水印图片两个方法
         */
        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,255,255,255);
                    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,255,255,255);
                    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);
                }
                else
                {
                    // 创建新图并拷贝
                    $this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
                    $white = ImageColorAllocate($this->h_dst,255,255,255);
                    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,255,255,255);
                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[1], $c[2]);
                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[1], $c[2], $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版本>4.3.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, 4096);
                }
                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    十六进制颜色
         */
        function _parseColor($color)
        {
            $arr = array();
            for($ii=1; $ii<strlen ($color); $ii++)
            {
                $arr[] = hexdec(substr($color,$ii,2));
                $ii++;
            }
     
            Return $arr;
        }
     
        /**
         * 计算出位置坐标
         */
       ?>

    上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一页  >> 


    Google
     
    文章录入:丹峰    责任编辑:丹峰 
  • 上一篇文章:

  • 下一篇文章:
  •  
    设为首页 / 加入收藏 / 联系站长 / 友情链接 / 本站动态 / 用户留言 / 版权申明
    QQ宝页站 www.QQBye.com 信息备案:粤ICP备06124483号