相关疑难解决方法(0)

PHP函数imagettftext()和unicode

我正在使用PHP函数imagettftext()将文本转换为GIF图像.我转换的文本包含Unicode字符,包括日语.在我的本地机器(Ubuntu 7.10)上一切正常,但在我的webhost服务器上,日文字符被破坏了.可能导致差异的原因是什么?一切都应编码为UTF-8.

webhost服务器上的破碎图像:http: //www.ibeni.net/flashcards/imagetest.php

从我的本地机器复制正确的图像:http: //www.ibeni.net/flashcards/imagetest.php.gif

我本地机器上的phpinfo()副本:http: //www.ibeni.net/flashcards/phpinfo.php.html

我的webhost服务器上的phpinfo()副本:http: //example5.nfshost.com/phpinfo

码:

mb_language('uni');
mb_internal_encoding('UTF-8');

header('Content-type: image/gif');

$text = '???';
$font = './Cyberbit.ttf';

// Create the image
$im = imagecreatetruecolor(160, 160);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// Create some colors
imagefilledrectangle($im, 0, 0, 159, 159, $white);

// Add the text
imagettftext($im, 12, 0, 20, 20, $black, $font, $text);
imagegif($im);
imagedestroy($im); 
Run Code Online (Sandbox Code Playgroud)

php unicode gd

11
推荐指数
2
解决办法
2万
查看次数

GD Library imagettftext在Gujarati语言文本中遇到问题

我用GD库创建了"Text on Image".我面临一个问题,即传递一些古吉拉特语文本,但输出错误如下:

我想要这样

在此输入图像描述

得到:

在此输入图像描述

我的代码是:

        $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, …
Run Code Online (Sandbox Code Playgroud)

php gd utf-8 gdlib image-text

5
推荐指数
1
解决办法
165
查看次数

标签 统计

gd ×2

php ×2

gdlib ×1

image-text ×1

unicode ×1

utf-8 ×1