添加到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  

    <?php
    /**
     *  图片水印类
     *
     *  Copyright PhpUp Studio, http://phpup.com, iasky
     *
     *  $Id: PhpUpImageWater.php,v 1.00 2006/4/19/ 21:00:57 iasky Exp $
     */
    class PhpUpImageWater
    {
        var $groundImage;
        var $groundImageWidth;
        var $groundImageHeight;
        var $groundImageHandle;
        var $waterType;
        var $waterPosType;
        var $waterPosX;
        var $waterPosY;
        var $waterWidth;
        var $waterHeight;
        var $waterImage;
        var $waterImageType;
        var $waterImageHandle;
        var $waterImageAlpha;
        var $waterText;
        var $waterTextColor;
        var $waterTextSize;
        var $waterTextFont;
        var $errorMsg;

        function PhpUpImageWater($groundImage = "1.jpg", $waterPosType = 0)
        {
            if(false == file_exists($groundImage))
            {
                $this->throwError("groundImage404");
            }
            $this->checkGD();
            $this->groundImage   =  &$groundImage;
            $this->waterType     =  &$waterType;
            $this->waterPosType  =  &$waterPosType;
            $this->setGroundImageInfo();
        }

        function checkGD()
        {
            if(false == function_exists("gd_info"))
            {
                $this->throwError("NonGD");
            }
        }

        function setGroundImageInfo()
        {
            $groundImageType   =  getimagesize($this->groundImage);
            $this->groundImageWidth  =  $groundImageType[0];
            $this->groundImageHeight =  $groundImageType[1];
            $this->groundImageType   =  $groundImageType[2];
            if($this->groundImageWidth < 150 or $this->groundImageHeight < 150)
            {
                $this->throwError("TooSmall");
            }
        }

        function setWaterTextInfo($waterText = "QQBYE.com",$waterTextColor = "#000000", $waterTextSize = "5", $waterTextFont = "../FZJLJT.FON")
        {
            $this->waterType     =  0;
            if(strlen($waterTextColor) == 7)
            {
                $this->waterTextColor = &$waterTextColor;
            }
            else
            {
                $this->throwError("WrongColor");
            }
            $this->waterText       =   &$waterText;
            $this->waterTextSize   =   &$waterTextSize;
            $this->waterTextFont   =   &$waterTextFont;
            $waterTextInfo = imagettfbbox(ceil($this->waterTextSize*1.2), 0, $this->waterTextFont, $this->waterText); 
            $this->waterWidth    =  $waterTextInfo[4] - $waterTextInfo[6]; 
            $this->waterHeight   =  $waterTextInfo[1] - $waterTextInfo[7]; 
            unset($waterTextInfo);
        }

        function setWaterImageInfo($waterImage = "logo.gif")
        {
            if(file_exists($waterImage))
            {
                $this->waterType       =   1;
                $this->waterImage      =   &$waterImage;
                $waterImageInfo        =   getimagesize($this->waterImage);
                $this->waterWidth      =   $waterImageInfo[0];
                $this->waterHeight     =   $waterImageInfo[1];
                $this->waterImageType  =   $waterImageInfo[2];
                unset($waterImageInfo);
            }
            else
            {
                $this->throwError("waterImage404");
            }
        }

        function setWaterPos()
        {
            switch($this->waterPosType) 
            { 
                case 0://随机 
                    $this->waterPosX = rand(0,($this->groundImageWidth - $this->waterWidth)); 
                    $this->waterPosY = rand(0,($this->groundImageHeight - $this->waterHeight)); 
                    break; 
                case 1://1为顶端居左 
                    $this->waterPosX = 0; 
                    $this->waterPosY = 0; 
                    break; 
                case 2://2为顶端居中 
                    $this->waterPosX = ($this->groundImageWidth - $this->waterWidth) / 2; 
                    $this->waterPosY = 0; 
                    break; 
                case 3://3为顶端居右 
                    $this->waterPosX = $this->groundImageWidth - $this->waterWidth; 
                    $this->waterPosY = 0; 
                    break; 
                case 4://4为中部居左 
                    $this->waterPosX = 0; 
                    $this->waterPosY = ($this->groundImageHeight - $this->waterHeight) / 2; 
                    break; 
                case 5://5为中部居中 
                    $this->waterPosX = ($this->groundImageWidth - $this->waterWidth) / 2; 
                    $this->waterPosY = ($this->groundImageHeight - $this->waterHeight) / 2; 
                    break; 
                case 6://6为中部居右 
                    $this->waterPosX = $this->groundImageWidth - $this->waterWidth; 
                    $this->waterPosY = ($this->groundImageHeight - $this->waterHeight) / 2; 
                    break; 
                case 7://7为底端居左 
                    $this->waterPosX = 0; 
                    $this->waterPosY = $this->groundImageHeight - $this->waterHeight * rand(115,125) / 100; 
                    break; 
                case 8://8为底端居中 
                    $this->waterPosX = ($this->groundImageWidth - $this->waterWidth) / 2; 
                    $this->waterPosY = $this->groundImageHeight - $this->waterHeight * rand(115,125) / 100; 
                    break; 
                case 9://9为底端居右 
                    $this->waterPosX = $this->groundImageWidth - $this->waterWidth; 
                    $this->waterPosY = $this->groundImageHeight - $this->waterHeight * rand(115,120) / 100; 
                    break; 
                default://随机 
                    $this->waterPosX = rand(0,($this->groundImageWidth - $this->waterWidth)); 
                    $this->waterPosY = rand(0,($this->groundImageHeight - $this->waterHeight));     
            }
        }

        function setGroundImageHandle()
        {
            switch($this->groundImageType) 
            {
                case 1:
                    $this->groundImageHandle = imagecreatefromgif($this->groundImage);
                    break; 
                case 2:
                    $this->groundImageHandle = imagecreatefromjpeg($this->groundImage);
                    break; 
                case 3:
                    $this->groundImageHandle = imagecreatefrompng($this->groundImage);
                    break; 
                default:
                    $this->throwError("NonType"); 
            }
        }

        function setWaterImageHandle()
        {
            switch($this->waterImageType) 
            {
                case 1:
                    $this->waterImageHandle = imagecreatefromgif($this->waterImage);
                    break; 
                case 2:
                    $this->waterImageHandle = imagecreatefromjpeg($this->waterImage);
                    break; 
                case 3:
                    $this->waterImageHandle = imagecreatefrompng($this->waterImage);
                    break; 
                default:
                    $this->throwError("NonType"); 
            }
        }

        function putWateredImage($extFileName)
        {
            switch($this->groundImageType) 
            {
                case 1:
                    imagegif($this->groundImageHandle, $extFileName.$this->groundImage);
                    break; 
                case 2:
                    imagejpeg($this->groundImageHandle, $extFileName.$this->groundImage);
                    break; 
                case 3:
                    imagepng($this->groundImageHandle, $extFileName.$this->groundImage);
                    break; 
                default:
                    $this->throwError("NonType"); 
            }        
        }

        function destroyHandle()
        {
            imagedestroy($this->groundImageHandle);
            if(isset($this->waterImageHandle))
            {
                imagedestroy($this->waterImageHandle);
            }
        }

        function makeWater($extFileName = "")
        {
            $this->setGroundImageHandle();
            $this->setWaterPos();
            imagealphablending($this->groundImageHandle, true); 
            if($this->waterType == 0)
            {
                imagettftext($this->groundImageHandle, $this->waterTextSize, 0, $this->waterPosX, $this->waterHeight + $this->waterPosY, imagecolorallocate($this->groundImageHandle, hexdec(substr($this->waterTextColor,1,2)), hexdec(substr($this->waterTextColor,3,2)), hexdec(substr($this->waterTextColor,5,2))), $this->waterTextFont, $this->waterText);
            }
            else
            {
                $this->setWaterImageHandle();
                imagecopy($this->groundImageHandle,$this->waterImageHandle , $this->waterPosX, $this->waterPosY, 0, 0, $this->waterWidth,$this->waterHeight);
            }
            //@unlink($this->groundImage);
            $this->putWateredImage($extFileName);
            $this->destroyHandle();
        }

        function throwError($errType)
        {
            switch($errType)
            {
                case "TooSmall":
                    $this->errorMsg = "要打水印图片太小";
                    break;
                case "groundImage404":
                    $this->errorMsg = "要打水印图片不存在";
                    break;
                case "waterImage404":
                    $th

    ?>

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


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

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