当前位置: 首页 > 2007年12月26日发布的所有文章
  • 一个简单的图片水印的类

    PHP代码
    1. /************************************************/  
    2. /*功能:添加图片水印 */  
    3. /*作者:还珠楼主 */  
    4. /*Email:dongxin1390008@163.com */  
    5. class digital   
    6. {   
    7. public $water_w,$water_h;//水印的宽,高   
    8. public $des_w,$des_h;//目标图片的宽高   
    9. public $pos_x,$pos_y;//落点坐标   
    10. public $water_url;//水印URL   
    11. public $des_url;//目标URL   
    12. public $water_info;//水印的基本信息   
    13. public $des_info;//目标图片信息   
    14. public $des,$water;   
    15. function __construct($des_url,$water_url=“images/dig3.png”)   
    16. {   
    17. $this->water=imagecreatefrompng($water_url);   
    18. $this->des=imagecreatefromjpeg($des_url);   
    19. $this->water_info=$this->getXY($water_url);   
    20. $this->des_info=$this->getXY($des_url);   
    21. $this->water_w=$this->water_info[0];   
    22. $this->water_h=$this->water_info[1];   
    23. $this->des_w=$this->des_info[0];   
    24. $this->des_h=$this->des_info[1];   
    25. $this->pos_x=5;   
    26. $this->pos_y=5;   
    27.   
    28. }   
    29. function getXY($img)   
    30. {   
    31. return getimagesize($img);   
    32. }   
    33.   
    34. function addDigital($br=true,$bl=false,$tl=false,$tr=false,$mid=false)   
    35. {   
    36. /***************bootom-right**********/  
    37. if($br)   
    38. {   
    39. $this->pos_x=$this->des_w-$this->water_w;   
    40. $this->pos_y=$this->des_h-$this->water_h;   
    41. imagecopymerge($this->des,$this->water,$this->pos_x,$this->pos_y,0,0,$this->water_w,$this->water_h,100);   
    42. }   
    43. /************bottom-left****************/  
    44. if($bl)   
    45. {   
    46. $this->pos_y=$this->des_h-$this->water_h;   
    47. imagecopymerge($this->des,$this->water,0,$this->pos_y,0,0,$this->water_w,$this->water_h,100);   
    48. }   
    49. /**************top-left******************/  
    50. if($tl)   
    51. {   
    52. imagecopymerge($this->des,$this->water,0,0,0,0,$this->water_w,$this->water_h,100);   
    53. }   
    54. /******************top-right************/  
    55. if($tr)   
    56. {    
    57. $this->pos_x=$this->des_w-$this->water_w;   
    58. imagecopymerge($this->des,$this->water,$this->pos_x,0,0,0,$this->water_w,$this->water_h,100);   
    59. }   
    60. /********************middle************/  
    61. if($mid)   
    62. {   
    63. $this->pos_x=($this->des_w-$this->water_w)/2;   
    64. $this->pos_y=($this->des_h-$this->water_h)/2;   
    65. imagecopymerge($this->des,$this->water,$this->pos_x,$this->pos_y,0,0,$this->water_w,$this->water_h,100);   
    66. }   
    67. imagejpeg($this->des);   
    68. header(“Content-type: image/jpeg”);   
    69.   
    70. }   
    71.   
    72. }   
    73. ?>   

     

     

    PHP代码
    1. include_once(“function/digital_class.php”);   
    2. $dig=new digital(“images/2.jpg”);   
    3. $dig->addDigital(true,false,false,false,false);   
    4. ?>   
    ]]>

    键盘游走者 发布于 2007-12-26 19:17php抢沙发