PHP背景水印图片生成代码

来源:互联网 发布:中国依赖进口数据 编辑:程序博客网 时间:2024/05/22 11:54

php背景水印图片生成代码

转自
http://www.75271.com/1150.html

php背景水印图片生成代码

  1. /**
  2. *@author:yangtao
  3. *@date:2016-08-12
  4. *@content: 背景水印
  5. */
  6. public function getbgwatermark(){
  7.  
  8. $imgWidth = 150;
  9. $imgHeight = 150;
  10. $img = imagecreatetruecolor($imgWidth, $imgHeight);
  11. $bgcolor = imagecolorallocate($img,255,255,255);
  12. imagefill($img, 0, 0, $bgcolor);
  13.  
  14. $text = imagecreatetruecolor($imgWidth, $imgHeight);
  15. imagefill($text, 0, 0, $bgcolor);
  16. $font_size = 10;
  17. $font_name = VENDOR_PATH."topthink/think-captcha/assets/ttfs/1.ttf";
  18. $ucode = $this->getUserinfo('userCode');
  19. if($ucode=="") $ucode = "测试文字";
  20. $font_color = imagecolorallocate($img, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));
  21. imagettftext($text, $font_size, 50, 10,90, $font_color, $font_name, $ucode);
  22.  
  23. imagecopymerge($img,$text,0,0,0,0,$imgWidth,$imgHeight,20);
  24.  
  25. header('content-type:image/png');
  26. imagepng($img);
  27. imagedestroy($img);
  28. }

0 0
原创粉丝点击