喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: 生成水印的類  
 
meteor_shower
高级会员
Rank: 4
揮刀戲江湖譜寫情緣傳奇


UID 66798
精华 2
积分 977
帖子 913
金钱 947 喜悦币
威望 30
人脉 0
阅读权限 50
注册 2005-9-21
来自 深圳
状态 离线
[广告]: q m
生成水印的類



<?php
Define
("STREAM"0);
    
Define("HANDLE"1);
    
Define("FILE_JPEG"2);
    
Define("FILE_GIF"3);
    
Define("FILE_PNG"4);
    
Define("FILE_WBMP"5);
    
Define("FILE_XBM"6);
    
Define("FILE_XPM"7);
    
Define("IMG_JPEG"8);
    
Define("IMG_PNG"9);
    
Define("IMG_GIF"10);
    
    
    class 
RWatermark 
    
{
        var 
$original_image = -1;
        var 
$mark_image = -1;
        var 
$marked_image = -1;
        var 
$original_width;
        var 
$original_height;
        var 
$mark_width;
        var 
$mark_height;
        var 
$mark_position "RND";
        var 
$mark_offset_x 0;
        var 
$mark_offset_y 0;
        var 
$transparent_color = -1
        var 
$transparency 100;
        var 
$gd_version;
        var  
$version 'RWatermark 0.92';




function 
RWatermark($type$str
        {
            
$this->setGDInfo();
            
            
$type StrToUpper($type);
            switch (
$type)
            {
                case 
STREAM:
                    
$this->original_image ImageCreateFromString($str);
                    break;
                case 
FILE_JPEG:
                    
$this->original_image ImageCreateFromJPEG($str);
                    break;
                case 
FILE_GIF:
                    
$this->original_image ImageCreateFromGIF($str);
                    break;
                case 
FILE_PNG:
                    
$this->original_image ImageCreateFromPNG($str);
                    break;
                case 
FILE_WBMP:
                    
$this->original_image ImageCreateFromWBMP($str);
                    break;
                case 
FILE_XBM:
                    
$this->original_image ImageCreateFromXBM($str);
                    break;
                case 
FILE_XPM:
                    
$this->original_image ImageCreateFromXPM($str);
                    break;
                case 
HANDLE:
                    
$this->mark_image $str;
                    break;
                default:
                    
$this->dieError("Unknown input type in constructor method!");
                    return 
false;
            }
            
            if (!
$this->original_image)
            {
                
$this->dieError("GD command error in constructor method!");
                return 
false;
            }
            
$this->original_width ImageSX($this->original_image);
            
$this->original_height ImageSY($this->original_image);
            
            return 
true;
        }




function 
AddWatermark($type$str
        {
            
$type StrToUpper($type);
            switch (
$type)
            {
                case 
STREAM:
                    
$this->mark_image ImageCreateFromString($str);
                    break;
                case 
FILE_JPEG:
                    
$this->mark_image ImageCreateFromJPEG($str);
                    break;
                case 
FILE_GIF:
                    
$this->mark_image ImageCreateFromGIF($str);
                    break;
                case 
FILE_PNG:
                    
$this->mark_image ImageCreateFromPNG($str);
                    break;
                case 
FILE_WBMP:
                    
$this->mark_image ImageCreateFromWBMP($str);
                    break;
                case 
FILE_XBM:
                    
$this->mark_image ImageCreateFromXBM($str);
                    break;
                case 
FILE_XPM:
                    
$this->mark_image ImageCreateFromXPM($str);
                    break;
                case 
HANDLE:
                    
$this->mark_image $str;
                    break;
                default:
                    
$this->dieError("Unknown input type in addWatermark method!");
                    return 
false;
            }
            
            if (!
$this->mark_image)
            {
                
$this->dieError("GD command error in addWatermark method!");
                return 
false;
            }
            
            
$this->mark_width ImageSX($this->mark_image);
            
$this->mark_height ImageSY($this->mark_image);
            
                        
$this->getOffsets();
            
           
            
$this->createMarkedImage();
            
            return 
true;
        }




function 
GetMarkedImage($type HANDLE$param1 ""$param2 ""$param3 ""
        {
            if (
$this->marked_image != -1)
            {
                
$type StrToUpper($type);
                switch (
$type)
                {
                    case 
HANDLE:
                        return 
$this->marked_image;
                    case 
IMG_PNG:
                        if (
$param1 != "") {ImagePNG($this->marked_image$param1);}
                        else {
ImagePNG($this->marked_image);}
                        return 
true;
                    case 
IMG_GIF:
                        if (
$param1 != "") {ImageGIF($this->marked_image$param1);}
                        else {
ImageGIF($this->marked_image);}
                        return 
true;
                    case 
IMG_JPEG:
                        if (
StrToUpper($param3) == "YES") {ImageInterlace($this->marked_image1);} 
                        else {
ImageInterlace($this->marked_image0);}
                        if (
$param2 == "") {$param2 75;}
                        
ImageJPEG($this->marked_image$param1$param2);
                        return 
true;
                    default:
                        
$this->dieError("Unknown output type in getMarkedImage method!");
                }
            }
            return 
false;
        }


function 
SetPosition($newposition "RND"$x 0$y 0)
        {
            
$valid_positions = array("TL""TM""TR""CL""CM""CR""BL""BM""BR""ABS""RND");
    
            
$newposition StrToUpper($newposition);
    
            if (
In_Array($newposition$valid_positions)) 
            {
                
$this->mark_position $newposition;
                if (
$this->mark_position == "ABS")
                {
                    
$this->mark_offset_x $x;
                    
$this->mark_offset_y $y;
                }
                return 
true;
            }
            return 
false;
        }


function 
SetTransparency($trans)
        {
            if ((
$trans >= 0) && ($trans <= 100))
            {
                
$this->transparency 100 $trans;
                return 
true;
            }
            return 
false;
        }


function 
SetTransparentColor($r,$g,$b)
        {
            if ((
$r >= 0) && ($r <= 255) && ($g >= 0) && ($g <= 255) && ($b >= 0) && ($b <= 255))
            {
                
$this->transparent_color = ($r << 16) + ($g << 8) + $b;
                return 
true;
            }
            return 
false;
        }

function 
Destroy()
        {
            if (
$this->original_image != -1) {ImageDestroy($this->original_image);}
            if (
$this->marked_image != -1) {ImageDestroy($this->marked_image);}
            if (
$this->mark_image != -1) {ImageDestroy($this->mark_image);}
        }








function 
createMarkedImage()
        {
                        
$this->marked_image ImageCreateTrueColor($this->original_width$this->original_height);
            
ImageCopy($this->marked_image$this->original_image0000$this->original_width$this->original_height);
            
                if (
$this->transparent_color != -1)
                {
                    
$transparent_color_index ImageColorExact($this->mark_image, ($this->transparent_color >> 16) & 0xFF, ($this->transparent_color >> 8) & 0xFF$this->transparent_color 0xFF);
                    
ImageColorTransparent($this->mark_image,$transparent_color_index);
                }
                if (
$this->gd_version >= 2)                 { 
                    
ImageAlphaBlending($this->marked_imagetrue);
                } 
                
ImageCopyMerge($this->marked_image$this->mark_image$this->mark_offset_x$this->mark_offset_y00$this->mark_width$this->mark_height$this->transparency);
        }
    
    
        function 
getOffsets() 
        {
            
$width_left $this->original_width $this->mark_width;
            
$height_left $this->original_height $this->mark_height
        
            switch (
$this->mark_position
            {
                case 
"TL":                     $this->mark_offset_x $width_left >= $width_left;
                    
$this->mark_offset_y $height_left >= $height_left;
                    break;
                case 
"TM":                     $this->mark_offset_x intval(($this->original_width $this->mark_width) / 2);
                    
$this->mark_offset_y $height_left >= $height_left;
                    break;
                case 
"TR":                     $this->mark_offset_x $this->original_width $this->mark_width;
                    
$this->mark_offset_y $height_left >= $height_left;
                    break;
                case 
"CL":                     $this->mark_offset_x $width_left >= $width_left;
                    
$this->mark_offset_y intval(($this->original_height $this->mark_height) / 2);
                    break;
                case 
"CM":                     $this->mark_offset_x intval(($this->original_width $this->mark_width) / 2);
                    
$this->mark_offset_y intval(($this->original_height $this->mark_height) / 2);
                    break;
                case 
"CR":                     $this->mark_offset_x $this->original_width $this->mark_width;
                    
$this->mark_offset_y intval(($this->original_height $this->mark_height) / 2);
                    break;
                case 
"BL":                     $this->mark_offset_x $width_left >= $width_left;
                    
$this->mark_offset_y $this->original_height $this->mark_height 5;
                    break;
                case 
"BM":                     $this->mark_offset_x intval(($this->original_width $this->mark_width) / 2);
                    
$this->mark_offset_y $this->original_height $this->mark_height 5;
                    break;
                case 
"BR":                     $this->mark_offset_x $this->original_width $this->mark_width 5;
                    
$this->mark_offset_y $this->original_height $this->mark_height 5;
                    break;
                case 
"ABS":                     $this->mark_offset_x = ($this->mark_offset_x >= 0) && ($this->mark_offset_x <= $width_left) ? $this->mark_offset_x 0;
                    
$this->mark_offset_y = ($this->mark_offset_y >= 0) && ($this->mark_offset_y <= $height_left) ? $this->mark_offset_y 0;
                    break;
                case 
"RND":
                    
$this->mark_offset_x Rand(5$width_left 5);
                    
$this->mark_offset_y Rand(5$height_left 5);
                    break;
            }
        }
        
        
        function 
dieError($err)
        {
            Die(
$err);
        }
        
        
        function 
setGDInfo()
        {
            
$gdinfo gd_info();
            if (
PReg_Match('/(d).d/'$gdinfo["GD Version"], $gdinfo)) {$this->gd_version $gdinfo[1];}
            else {
$this->gd_version 0;}
            UnSet(
$gdinfo);
        }
    }
?>
2006-3-2 02:15 PM#1
查看资料  Blog  发短消息  QQ  顶部
 
meteor_shower
高级会员
Rank: 4
揮刀戲江湖譜寫情緣傳奇


UID 66798
精华 2
积分 977
帖子 913
金钱 947 喜悦币
威望 30
人脉 0
阅读权限 50
注册 2005-9-21
来自 深圳
状态 离线
[推荐阅读] 如何从邮件服务器中取得即时信息文件?
使用方法

<?php
$handle 
= new RWatermark(FILE_JPEG"./105975a699e.jpg");
    
    
$handle->SetPosition("RND");
    
$handle->SetTransparentColor(2550255);
    
$handle->SetTransparency(60);
    
$handle->AddWatermark(FILE_PNG"./23.png");
    
    
Header("Content-type: image/png");
    
$handle->GetMarkedImage(IMG_PNG);
    
$handle->Destroy();
?>
2006-3-2 02:17 PM#2
查看资料  Blog  发短消息  QQ  顶部
 
我不是鱼
注册会员
Rank: 2
初级会员



UID 68877
精华 0
积分 151
帖子 100
金钱 151 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2006-2-25
来自 1
状态 离线
[推荐阅读] Non-static method
为什么会提示
Fatal error: Call to undefined function: gd_info()




php爱好者论坛
http://www.phpfans.net
2006-3-2 02:52 PM#3
查看资料  发短消息  顶部
 
bqsc
乞丐




UID 71560
精华 0
积分 -1
帖子 1
金钱 -1 喜悦币
威望 0
人脉 0
阅读权限 1
注册 2006-4-13
状态 离线
[推荐阅读] 为什么有的版区锁住了?
还真是复杂啊
2006-4-26 02:46 PM#4
查看资料  发短消息  顶部
 
jingzhi (jingzhi)
注册会员
Rank: 2
中级会员



UID 30401
精华 0
积分 174
帖子 178
金钱 174 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-8-6
状态 离线
[推荐阅读] 域名都注册不到,郁闷!
还不错,如果效率再快点儿就更好
2006-5-10 11:59 AM#5
查看资料  发短消息  顶部
 
flyer_2001
新手上路
Rank: 1



UID 76661
精华 0
积分 0
帖子 5
金钱 0 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2006-7-18
状态 离线
[推荐阅读] 哪个好
学习中。。。
2006-8-29 04:44 PM#6
查看资料  发短消息  顶部
 
gonggui
新手上路
Rank: 1



UID 76410
精华 0
积分 5
帖子 7
金钱 5 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2006-7-13
状态 离线
[推荐阅读] 急!!!!!!!!!!!!!!!!!如何在网页中嵌入ubb编辑器?
很好!我很喜欢。
2006-9-13 08:57 AM#7
查看资料  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.096540 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP