首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >古吉拉特文文本中的GD Library imagettftext获取问题

古吉拉特文文本中的GD Library imagettftext获取问题
EN

Stack Overflow用户
提问于 2019-01-27 15:17:28
回答 1查看 425关注 0票数 5

我已经使用GD Library创建了“图像上的文本”。我面临一个问题,传递一些古吉拉特语文本,但得到错误的输出,如下所示:

我想要这样

并获得:

我的代码是:

代码语言:javascript
复制
        $textBox = imagettfbbox($fontSize, $angle, $font, $txt);

        $textWidth = abs(max($textBox[2], $textBox[5]));

        $textHeight = abs(max($textBox[5], $textBox[7]));

        $x = (imagesx($this->img) - $textWidth)/2;

        $y = ((imagesy($this->img) + $textHeight)/$h)-($lines-2)*$textHeight;

        $lines = $lines-1;

        // Added this line from SO answer.
        $txt = mb_convert_encoding($txt, "HTML-ENTITIES", "UTF-8");
        $txt = preg_replace('~^(&([a-zA-Z0-9]);)~', htmlentities('${1}'), $txt);

        //add some shadow to the text
        imagettftext($this->img, $fontSize, $angle, $x + 2, $y + 1, $white, $font, $txt);

        //add the text
        imagettftext($this->img, $fontSize, $angle, $x, $y, $maroon, $font, $txt);

我已经在上面的代码中尝试过this answer,但不起作用。

有谁能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2019-02-05 14:24:07

我已经为你的给定文本创建了示例,我已经使用了其他字体。您需要匹配字符映射才能显示正确的文本:

代码语言:javascript
复制
<?php
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'xF]EZF+L';
// Replace path by your own font path
$font = __DIR__ . '/LMG-Arun.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);

您可以添加您的字体和样式。对于字符映射,请遵循以下url:https://fonts.webtoolhub.com/font-n48283-lmg-arun.aspx

输出:

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54385917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档