TP中的图片水印

时间:2022-05-03 17:46:38
         $img_dir = ROOT_PATH . 'public/upload/card/' . $data['jt_id'];  //创建合成图片存放位置
      //自动创建文件夹
if (!file_exists($img_dir)) {
mkdir($img_dir, 0755, true);
}
if($data){
$tg_price = $data['tg_price']; //原价
$re_price = '零售价¥'.$data['re_price']; //实际售价
$goods_pic = $data['goods_pic'];//商品图片 if(strlen($data['createTime'])>14){
$endtime = ':'.' '.(substr($data['createTime'],-15));
}else{
$endtime =':'.' '.$data['createTime'];//结束时间
} }
//创建水印图片存放位置
$pic_path = ROOT_PATH . 'public/upload/card/' . $data['jt_id'].'/'.$data['jt_id'].'.png';
//获取到图片路径
$img = file_get_contents($goods_pic);
$photo = file_put_contents($pic_path,$img); //将图片放入到指定的目录下
//将图片写入文件
if($photo){
//生成缩略图
$image = Image::open($pic_path);
$image->thumb(328,158)->save($pic_path);
//打开要处理的图片
$pic = Image::open('./static/img/tuangou.png');
//水印图片
$xy_pic = [52,65];
$pic->water($pic_path,$xy_pic)->save($img_dir.'/water.png');
//团购价
$xy_price = [92,226];
$pic->text($tg_price,'./static/img/HATTEN_0.TTF',50,'#F51B51',$xy_price )->save($img_dir.'/water.png');
//零售价
$xy_re_price = array(215,240);
$pic->text($re_price,'./static/img/msyh.ttf',17,'#999999',$xy_re_price)->save($img_dir.'/water.png');
//原价的中划线
$xy_unline2 = [214,245];
$pic->text('______________','./static/img/msyh.ttf',18,'#999999',$xy_unline2)->save($img_dir.'/water.png');
//结束时间
$xy_endtime = array(164,310);
$pic->text($endtime,'./static/img/msyhbd(1).ttf',21,'#FFFFFF',$xy_endtime)->save($img_dir.'/water.png');
//输出结果
$url_card = config('website').'/upload/card/'.$data['jt_id'].'/water.png';
}