加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php利用gd库为图片添加水印

发布时间:2020-12-12 21:50:25 所属栏目:PHP教程 来源:网络整理
导读:本文实例为大家分享了php利用gd库为图片添加水印的方法,供大家参考,具体内容如下 //创建图片的实例 $dst = imagecreatefromstring(file_get_contents($dst_path)); $src = imagecreatefromstring(file_get_contents($src_path)); //获取水印图片的宽高 lis

本文实例为大家分享了php利用gd库为图片添加水印的方法,供大家参考,具体内容如下

//创建图片的实例
$dst = imagecreatefromstring(file_get_contents($dst_path));
$src = imagecreatefromstring(file_get_contents($src_path));
//获取水印图片的宽高
list($src_w,$src_h) = getimagesize($src_path);
//将水印图片复制到目标图片上,最后个参数50是设置透明度,这里实现半透明效果,两个20是控制水印坐标位置
imagecopymerge($dst,$src,20,$src_w,$src_h,50);
//如果水印图片本身带透明色,则使用imagecopy方法
//imagecopy($dst,10,$src_h);
//输出图片
list($dst_w,$dst_h,$dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1://GIF
header('Content-Type: image/gif');
imagegif($dst);
break;
case 2://JPG
header('Content-Type: image/jpeg');
imagejpeg($dst);
break;
case 3://PNG
header('Content-Type: image/png');
imagepng($dst);
break;
default:
break;
}
imagedestroy($dst);
imagedestroy($src);

?>

效果图:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读