[官方文档]
http://document.thinkphp.cn/manual_3_2.html#image
- 文字水印 本示例仅支持本地服务器里面的图片打水印
/**
* @param $text 打水印的文字内容
* @param $img 原图片路径 ( 打水印前的图片) 本地服务器里面的
* @param $size 文字大小
* @param $color 文字颜色
* @param $position 文字打印位置 (数组 $position = array(160,183) 第一个值:X坐标 第二个值:Y坐标)
* @param $file 图片文件名 (最终的图片文件名) 本地服务器里面的
* @return string
*/
public function water($text ,$img,$size,$color,$position,$file)
{
$image = new \Think\Image();
$tff = './Public/苹方字体.ttf';//字体路径
$time = time();
$image->open($img)->text($text,$tff,$size,$color,$position)->save($file);
return $file;
}
//多个文字水印 调用多次就好
$image = new \Think\Image();
$image->open($text['img'])
->text($text['name'],$tff,$text['size'],$text['color'],$text['position'])
->text($text['name'],$tff,$size2,$color2,$position2)
->water('./Public/images/ticket/sex.png',$position3,100)
->save($text['file']);
- 图片水印 本示例仅支持本地服务器里面的图片打水印
//$bg_img 背景图片 本地服务器里面的
//$position 水印位置 (数组 $position = array(160,183) 第一个值:X坐标 第二个值:Y坐标)
//$avater_file 水印图片 本地服务器里面的
//$html_file 保存的位置 及最终的图片地址 本地服务器里面
//$img_url 最终的图片地址 可外网访问
$image = new \Think\Image();
$image->open($bg_img)->water($avater_file,$position,100)->save($html_file);
$img_url = 'http://' . $_SERVER['HTTP_HOST'] .substr($html_file, 1);
``