tp3.2.3 图片打水印

2 篇文章 0 订阅
1 篇文章 0 订阅

[官方文档]
http://document.thinkphp.cn/manual_3_2.html#image

  1. 文字水印 本示例仅支持本地服务器里面的图片打水印
 	/**
     * @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']);
  1. 图片水印 本示例仅支持本地服务器里面的图片打水印
		//$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);

``

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值