PHP imagettftext _php tutorial for automatic line wrapping within a specified width

Source: Internet
Author: User
[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);


}


Author: Jiaochangyun

http://www.bkjia.com/PHPjc/478037.html www.bkjia.com true http://www.bkjia.com/PHPjc/478037.html techarticle [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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.