imagettftext字间距的问题

rob123 2008-09-18 05:10:55
用imagettftext生成带文字的图片,如果控制文字的每个字符之间的间距?
查阅了很多资料没有找到解决方法,请高手指教!

array imagettftext ( resource image, int size, int angle, int x, int y, int color, string fontfile, string text)

另外还有一个
array imagefttext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text [, array $extrainfo ] )

可以有额外的extrainfo,但是经过查阅发现目前只支持设置lineheight。

困惑。。
...全文
603 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2008-09-22
  • 打赏
  • 举报
回复
的确没有直接控制字间距之方法。

逐字书写吧。

@_@
东东车 2008-09-20
  • 打赏
  • 举报
回复
逐字书写....间距可调....通过$font_spacing调整
东东车 2008-09-20
  • 打赏
  • 举报
回复
逐字书写....间距可调....通过$font_spacing调整
东东车 2008-09-20
  • 打赏
  • 举报
回复
ͨ���ı�$font_spacing����������

<?php
// macleo 2008.9.20.Sat.
//������д....���ɵ�....ͨ��$font_spacing����

//defined ttf location and text will display
$font_path = "font/";
$font_name = $font_path."fzhc_GBK.ttf";
$font_size = 50;
$font_angle = 0 ;
$text = array("��","��","��","д","��","��","��","��");
$font_spacing = 25;//�ּ���������
$picname = "CanAdjust";
$position_x = 50;//first Character coordinate x;
$position_y = 70;//first Character coordinate x;
$font_shade_spacing_x = 3;
$font_shade_spacing_y = 3;
$im = imagecreatetruecolor(800, 100);

// colors
$white = imagecolorallocate($im, 0xff, 0xff, 0xff);
$grey = imagecolorallocate($im, 0x98, 0x98, 0x98);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

imagefilledrectangle($im, 0, 0, 800, 100, $white);
// line
imageline ( $im, 799, 0, 0, 0, $black );//top
imageline ( $im, 799, 99, 0, 99, $black );//bottom
imageline ( $im, 0, 99, 0, 0, $black );//left
imageline ( $im, 799, 99, 799, 0, $black );//right

// get weight of every character of Chinese
$font_coordinate = imagettfbbox ( $font_size, $font_angle, $font_name, $text[0] );
$font_weight = $font_coordinate[2] - $font_coordinate[0];
$font_height = abs($font_coordinate[5]) - $font_coordinate[3];

//output text from array
for($count = 0 ; $count<=count($text) ; $count++)
{
$arr = imagettftext($im, $font_size, $font_angle , $position_x , $position_y, $grey, $font_name, $text[$count]);
imagettftext($im, $font_size, $font_angle , $position_x-$font_shade_spacing_x , $position_y-$font_shade_spacing_y, $black, $font_name, $text[$count]);
$position_x = $position_x + $font_weight + $font_spacing;
}

header('Content-disposition: inline; filename='.$picname.'.png');
imagepng($im);
ImageDestroy($im);
?>
rob123 2008-09-18
  • 打赏
  • 举报
回复
@xuzuning

还是不行,能不能给一个简单的示例?
rob123 2008-09-18
  • 打赏
  • 举报
回复
可能我的处理方式有问题,我再试试。
rob123 2008-09-18
  • 打赏
  • 举报
回复
试过逐字书写,但程序卡在那不动了,不知道为什么。

或者说你们的逐字书写是怎么实现的?
xuzuning 2008-09-18
  • 打赏
  • 举报
回复
imagettfbbox -- 取得使用 TrueType 字体的文本的范围

imagettftext 逐字书写
程序猿之殇 2008-09-18
  • 打赏
  • 举报
回复
size决定间距吧
如果还不是理想的情况,自己人为控制.

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧