文字水印
文字水印就是在图片上加上文字,主要使用gd库的imagefttext方法,并且需要字体文件。效果图如下:
实现代码如下:
//创建图片的实例
$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;
}
imagedestroy($dst);
本文地址:https://www.stayed.cn/item/6026
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我