Home >Backend Development >PHP Tutorial >php imagettftext Automatically wrap lines within the specified width_PHP tutorial

php imagettftext Automatically wrap lines within the specified width_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:53:271694browse

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

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

 


作者:jiaochangyun

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478037.htmlTechArticle[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...
Statement:
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