图像设置水印

给图像设置水印

一,加载图片

//加载图片
$imgfile = "tsg.jpg";

二,读取图片

//将图片文件读取出来,存入到一个变量
$str = file_get_contents($imgfile);

三,创建图像

//创建图像
$img = imagecreatefromstring($str);
if($img === false){
	die('创建图像失败');
}

四,加水印

//加水印(在图像上输出字符)
$font = "STCAIYUN.TTF";
if(!file_exists($font)){
	die('字体库文件不存在');
}

$text = "XXX版权所有";
$color = imagecolorallocate($img,255,0,0);
imagettftext($img,30,0,150, 50, $color, $font, $text);
// header('content-type:image/png');
imagepng($img,'new-' . $imgfile);
imagedestroy($img);

echo '生成图像文件成功';

 

猜你喜欢

转载自blog.csdn.net/ZJP852/article/details/84616630