首页 >php教程 >php手册 >php imagettftext 规定宽度内自动换行

php imagettftext 规定宽度内自动换行

WBOY
WBOY原创
2016-06-13 10:51:302099浏览

[php]
函数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         { 
            $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]             { 
                $_string.=mb_substr($string,$i,1); 
            } 
            否则
            { 
                $__string.=$_string."n"; 
                $_string=mb_substr($string,$i,1); 
            } 
        } 
        $__string.=$_string;  
        $box=imagettfbbox($pos['fontsize'],0,$font_file,mb_substr($__string,0,1)); 
        图片ttftext(
            $卡,
            $pos['fontsize'],
            0,
            $pos['左'],
            $pos['top'] ($box[3]-$box[7]),
            $font_color,
            $font_file,
            $__string); 
         
         
    } 

函数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   {
   $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]    {
    $_string.=mb_substr($string,$i,1);
   }
   其他
   {
    $__string.=$_string."n";
    $_string=mb_substr($string,$i,1);
   }
  }
  $__string.=$_string;
  $box=imagettfbbox($pos['fontsize'],0,$font_file,mb_substr($__string,0,1));
  图片ttftext(
   $卡,
   $pos['字体大小'],
   0,www.2cto.com
   $pos['左'],
   $pos['top'] ($box[3]-$box[7]),
   $font_color,
   $font_file,
   $__string);
  
  
 }

 


作者:焦长云
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn