class Test extends IndexBase
{
protected $text = 'php网站程序开发';
//protected $font = {$_SERVER['DOCUMENT_ROOT']}.'/public/mui/fonts/mui.ttf'; //如果没有要自己加载到相应的目录下(本地www)
protected $angle = 0;
protected $size = 15;
protected $showX = 100;
protected $showY = 160;
protected $text0 = '2011 年 12 月 12 日';
protected $angle0 = 0;
protected $showX0 = 230;
protected $showY0 = 200;
protected $text1 = '新郎';
protected $angle1 = 20;
protected $showX1 = 135;
protected $showY1 = 285;
protected $text2 = '新娘';
protected $angle2 = 20;
protected $showX2 = 300;
protected $showY2 = 285;
protected $text3 = '北京市海淀区香格里拉酒店';
protected $angle3 = 0;
protected $showX3 = 120;
protected $showY3 = 445;
protected $text4 = '上午十一点整';
protected $angle4 = 0;
protected $showX4 = 305;
protected $showY4 = 480;
/**给图片添加文字水印
* @return mixed
*/
public function index()
{
//打开图片
//1配置图片路径(你想要操作的图片路径)
$src = $_SERVER['DOCUMENT_ROOT'].'/public/static/images/wutu.jpg';
//2获取图片信息(通过GD库提供的方法,得到你想要处理的图片基础信息)
$info = getimagesize($src);
/* echo "<pre>";
print_r($info);*/
//3通过图像编号获取图像类型 不加false 为.jpg 加false为jpg
$type= image_type_to_extension($info[2],false);
//4在内存中创建一个和我们图像类型一样的图像
$fun ="imagecreatefrom{
$type}";
//5把图片复制到内存
$image = $fun($src);
//操作图片
//1设置字体路径
$font = $_SERVER['DOCUMENT_ROOT'].'/public/static/fonts/simsun.ttf';
//2填写水印内容
$content = '航航';
$content = mb_convert_encoding($content, "html-entities", "utf-8");
//3设置字体的颜色和透明度 图片 颜色 透明度
$col = imagecolorallo
php中有关GD库的使用
最新推荐文章于 2022-11-10 16:28:09 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)