php imagettftext 规定宽度内自动换行

function draw_txt_to($card,$pos,$string)
	{
		 
		$font_color = imagecolorallocate($card, $pos['color'][0],$pos['color'][1],$pos['color'][2]);
		$font_file = BASEPATH.'../'.cfg('ttf');
		$_string='';
		$__string='';
		
		for($i=0;$i<mb_strlen($string);$i++)
		{
			$box=imagettfbbox($pos['fontsize'],0,$font_file,$_string);
			$_string_length=$box[2]-$box[0];
			$box=imagettfbbox($pos['fontsize'],0,$font_file,mb_substr($string,$i,1));
			
			if( $_string_length+$box[2]-$box[0]<$pos['width'])
			{
				$_string.=mb_substr($string,$i,1);
			}
			else
			{
				$__string.=$_string."\n";
				$_string=mb_substr($string,$i,1);
			}
		}
		$__string.=$_string; 
		$box=imagettfbbox($pos['fontsize'],0,$font_file,mb_substr($__string,0,1));
		imagettftext(
			$card,
			$pos['fontsize'],
			0,
			$pos['left'],
			$pos['top']+($box[3]-$box[7]),
			$font_color,
			$font_file,
			$__string);
		
		
	}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值