时间:2021-07-01 10:21:17 帮助过:2人阅读
function she_zhi_shui_ying($data){
// 图片地址
$dst_path = str_replace('public', 'storage', $data->path);
// 水印文字
$str = $data->mendian_men_dian_ping_pai.' '.$data->mendian_men_dian_hao.' '.$data->mendian_name."\n".date("Y-m-d H:i", strtotime($data->xun_kai_si_time)).'-'.date("H:i", strtotime($data->xun_jie_shu_time))."\n".$data->created_user_name."\n".$data->canshu_name;
$fileName = $this->wenn_jian_ming_cheng($dst_path);
$path = 'suiying/'.$fileName.'.jpg';
if(is_file($path)){
return $path;
}else{
// 获取图片信息
$image_info = getimagesize($dst_path);
// 图片高度
$imageHeight = $image_info[1];
// 图片宽度
$imageWidth = $image_info[0];
//创建图片的实例
$dst = imagecreatefromstring(file_get_contents($dst_path));
//打上文字
$font = 'fonts/msyhbd.ttf';//字体
$black = imagecolorallocatealpha($dst, 255, 255, 255, 63);//字体颜色
imagefttext($dst, 15, 0, 30, $imageHeight-80, $black, $font, $str);
//输出图片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1://GIF
header('Content-Type: image/gif');
imagegif($dst, $path);
break;
case 2://JPG
// header('Content-Type: image/jpeg');
// 显示
// imagejpeg($dst);
// 保存
imagejpeg($dst, $path);
break;
case 3://PNG
header('Content-Type: image/png');
imagepng($dst, $path);
break;
default:
break;
}
imagedestroy($dst);
return $path;
}
}相关推荐:
PHP的邮箱发送
PHP的数据类型
以上就是php图片水印的代码的详细内容,更多请关注Gxl网其它相关文章!