GD图像生成错误

发布于 2024-07-24 20:35:14 字数 1585 浏览 1 评论 0原文

我正在使用 GD 动态生成页面上标题图像的图像。 目前生成了 100 多张图像,其中绝大多数效果都很好。

最近,我们发现某些标题破坏了图像创建,在两个字符之间插入了较大的水平空间。

用于图像生成的字体是 Interstate,以下是一些有效的标题示例,以及一个损坏的示例。 在标题损坏的情况下,是由于字符“JB”彼此靠近而损坏了它。 翻转字符或在字符之间放置任意数量的字符会导致正确生成图像。

正如您从示例中看到的,标题适用于文本的短部分和长部分,只是到目前为止,只有一个示例打破了它,真的开始让我感到困惑,并怀疑字体文件或 GD 中存在错误,有什么建议吗?

替代文本 http://far.id.au/jkf/so/jb.png< /a> 替代文本 http://far.id.au/jkf/so/bj.png< /a> 替代文本 http://far.id.au/jkf/so/cheesecake.png< /a> 替代文本 http://far.id.au/jkf/so/blah.png< /a>

代码:

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);
}

I'm using GD to generate images on the fly for title images on the page. There are over 100 images generated at the moment, the vast majority of which work great.

Recently we found certain titles were breaking the image creation where a large horizontal space was inserted between 2 characters.

The font being used for image generation is Interstate, and following are some examples of the titles working, along with an example of a broken one. In the case of the broken title it was the characters "JB" near each other that broke it. Flipping the characters around or having any number of characters between them results in the image being generated correctly.

As you can see from the examples the titles work with both short and long portions of text, it's just that one example that breaks it so far, really starting to confuse me and suspecting a bug in either the font file or GD, any suggestions?

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

Code:

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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怼怹恏 2024-07-31 20:35:14

损坏的字体是罪魁祸首

Corrupt font was to blame

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文