php imagefttext 参数,PHP: imagefttext - Manual

I'm not sure if this is a PHP issue or an GD issue, but after upgrading to PHP 5.3.2, text written at an angle has become top-justified (so "N" and "n" have the same top, but the bottom of the "N" is lower than the bottom of the "n".  I've written a kludgy work-around, which writes the text to a non-rotated temporary image, then copies the temporary image, rotated onto the main image.  The kludginess is to get around the fact that I can't seem to extract the font info, particularly the distance between the baseline and the very bottom (I've hard-coded it as 30% of the font size)

I hope the bug can be fixed (if it is indeed a bug) or that others can improve this code:

//        $text = "Nlfbacejygq!";$bbox=imageftbbox($size,0,$fontfile,$text,$info);$dropdown=$size*0.3;$xsize=abs($bbox[2] -$bbox[0]);$ysize=abs($bbox[5] -$bbox[3]);$tmpImage=imagecreatetruecolor($xsize*1.25,$ysize*1.25);// need the extra space to accommodate risers and descenders$transparent=imagecolorallocate($tmpImage,255,255,154);

if (!$transparent) {error_log("Color allocate failed");

}imagecolortransparent($tmpImage,$transparent);

if (!imagefill($tmpImage,0,$ysize,$transparent)) {error_log("Fill failed");

}$rgb=imagecolorsforindex($image,$inColor);$color=imagecolorexact($tmpImage,$rgb['red'],$rgb['green'],$rgb['blue']);

if ($color== -1) {$color=imagecolorallocate($tmpImage,$rgb['red'],$rgb['green'],$rgb['blue']);

if (!$color) {error_log("Color allocate 2 failed");

}

}$newbbox=imagefttext($tmpImage,$size,0,0,$ysize*1.0,$color,$fontfile,$text,$info);$tmpImage=imagerotate($tmpImage,$angle,$transparent);$newWidth=imagesx($tmpImage);$newHt=imagesy($tmpImage);imagecopymerge($image,$tmpImage,$x-$newWidth+$dropdown,$y-$newHt,0,0,$newWidth,$newHt,100);//        Highlight the desired starting point (baseline) with a green dot:

//        $green = imagecolorallocate($image, 0, 251, 0);

//        imagefilledellipse($image, $x, $y, 10, 10, $green);imagedestroy($tmpImage);?>

-Dave

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值