转自
http://www.75271.com/1150.html
php背景水印图片生成代码
- /**
- *@author:yangtao
- *@date:2016-08-12
- *@content: 背景水印
- */
- public function getbgwatermark(){
-
- $imgWidth = 150;
- $imgHeight = 150;
- $img = imagecreatetruecolor($imgWidth, $imgHeight);
- $bgcolor = imagecolorallocate($img,255,255,255);
- imagefill($img, 0, 0, $bgcolor);
-
- $text = imagecreatetruecolor($imgWidth, $imgHeight);
- imagefill($text, 0, 0, $bgcolor);
- $font_size = 10;
- $font_name = VENDOR_PATH."topthink/think-captcha/assets/ttfs/1.ttf";
- $ucode = $this->getUserinfo('userCode');
- if($ucode=="") $ucode = "测试文字";
- $font_color = imagecolorallocate($img, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));
- imagettftext($text, $font_size, 50, 10,90, $font_color, $font_name, $ucode);
-
- imagecopymerge($img,$text,0,0,0,0,$imgWidth,$imgHeight,20);
-
- header('content-type:image/png');
- imagepng($img);
- imagedestroy($img);
- }