php文字水印和php图片水印实现代码(二种加水印方法)
php  /  管理员 发布于 7年前   246
文字水印 文字水印就是在图片上加上文字,主要使用gd库的imagefttext方法,并且需要字体文件。效果图如下: 实现代码如下: //创建图片的实例 //打上文字 //输出图片 imagedestroy($dst); 图片水印 图片水印就是将一张图片加在另外一张图片上,主要使用gd库的imagecopy和imagecopymerge。效果图如下: 实现代码如下: //创建图片的实例 //获取水印图片的宽高 //将水印图片复制到目标图片上,最后个参数50是设置透明度,这里实现半透明效果 //输出图片 imagedestroy($dst);
$dst_path = 'dst.jpg';
$dst = imagecreatefromstring(file_get_contents($dst_path));
$font = './simsun.ttc';//字体
$black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色
imagefttext($dst, 13, 0, 20, 20, $black, $font, '快乐编程');
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;
}
$dst_path = 'dst.jpg';
$src_path = 'src.jpg';
$dst = imagecreatefromstring(file_get_contents($dst_path));
$src = imagecreatefromstring(file_get_contents($src_path));
list($src_w, $src_h) = getimagesize($src_path);
imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50);
//如果水印图片本身带透明色,则使用imagecopy方法
//imagecopy($dst, $src, 10, 10, 0, 0, $src_w, $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($src);您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号