我正在使用GD为页面上的标题图像动态生成图像。目前生成了100多张图像,其中绝大多数效果很好。
最近我们发现,某些标题在2个字符之间插入了较大的水平空间,从而破坏了图像的创建。
正如你从例子中看到的,标题既适用于短文本部分,也适用于长文本部分,到目前为止,这只是一个打破它的例子,真的开始让我感到困惑,怀疑字体文件或GD中有错误,有什么建议吗?
alt text http://far.id.au/jkf/so/jb.png
alt text http://far.id.au/jkf/so/bj.png
alt text http://far.id.au/jkf/so/cheesecake.png
alt text http://far.id.au/jkf/so/blah.png
private function GenerateImage()
{
$height = 31;
$width = $this->Width;
$x = 10;
$y = 20;
$font_size = 10;
$text_colours = $this->ToRGB($this->TextColour);
$background_colours = $this->ToRGB($this->BackgroundColour);
$image = imagecreatetruecolor($width,$height);
$fg_color = imagecolorallocate($image,$text_colours[0],$text_colours[1],$text_colours[2]);
$bg_color = imagecolorallocate($image,$background_colours[0],$background_colours[1],$background_colours[2]);
imagefill($image,0,0,$bg_color);
imagettftext($image,$font_size,0,$x,$y,$fg_color,$this->Font,strtoupper($this->Title));
return imagepng($image,$this->FilePath,9);
}