一个简单的图片水印的类

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

 

 

PHP代码
  1. <?   
  2. include_once("function/digital_class.php");   
  3. $dig=new digital("images/2.jpg");   
  4. $dig->addDigital(true,false,false,false,false);   
  5. ?>   
posted @ 2007-12-26 19:17  二宝的博客  阅读(218)  评论(0编辑  收藏  举报