上一次写了PHP图像处理 imagestring添加图片水印,但是imagestring方法不能添加中文,所以现在使用imagettftext这个方法来添加中文。相比imagestring,imagettftext需要指定字体文件。

<?php
//1. 打开要加水印的图片
$image = imagecreatefromjpeg("001.jpg");
//2. 在画布中绘制图像
$bai = imagecolorallocate($image, 255, 255, 255);
//3. 设置水印文字
$text = 'abc我是水印123,。、
		!@#dasdasda1231';
//使用指定的字体文件绘制文字
//参数2:字体大小
//参数3:字体倾斜的角度
//参数4、5:文字的x、y坐标
//参数6:文字的颜色
//参数7:字体文件
//参数8:绘制的文字
imagettftext($image, 50, 0, 280, 1000, $bai, 'STXINGKA.TTF', $text);

//4. 在浏览器直接输出图像资源
header("Content-Type:image/jpeg");
imagejpeg($image);

//5. 销毁图像资源
imagedestroy($image);
?>

效果图:

PHP图像处理 imagettftext添加中文水印

相关文章: