Home > php教程 > php手册 > body text

php imagettftext 规定宽度内自动换行

WBOY
Release: 2016-06-13 10:51:30
Original
2043 people have browsed it

[php]
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         { 
            $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); 
            } 
            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); 
         
         
    } 

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   {
   $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);
   }
   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,www.2cto.com
   $pos['left'],
   $pos['top']+($box[3]-$box[7]),
   $font_color,
   $font_file,
   $__string);
  
  
 }

 


作者:jiaochangyun
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!