php文字怎么居中,PHP图像字符水印居中

[php]

//让图像上字符串居中

header("content-type:text/html;charset = utf-8");

//(1)创建画布

$filename = "./images/02.jpg";

$img = imagecreatefromjpeg($filename);

$str = "WELCOME to liuguofeng.com";

$font = 5;

//(2)分配颜色:

$color1 = imagecolorallocate($img,255,0,255);

$color2 = imagecolorallocate($img,255,0,255);

//(3)获取画布宽度和高度

$imgWidth = imagesx($img);

$imgHeight = imagesy($img);

//(4)获取字体尺寸

$fontWidth = imagefontwidth($font);

$fontHeight = imagefontheight($font);

//(5)计算字符串的起始坐标

$x = ($imgWidth-$fontWidth*strlen($str))/2;

$y = ($imgHeight-$fontHeight)/2;

//(6)写入一个字符串

imagestring($img,$font,$x,$y,$str,$color1);

header("content-type:image/jpeg");

imagejpeg($img);

//(7)关闭图像

imagedestroy($img);

?>

[/php]

63604d1f137b3f6feec0d9d0a3955a74.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值