Maison > php教程 > php手册 > le corps du texte

php imagettftext 规定宽度内自动换行

WBOY
Libérer: 2016-06-13 10:51:30
original
2044 Les gens l'ont consulté

[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
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!