PHP图像使用UTF-8字符创建

时间:2013-10-09 07:40:00

标签: php utf-8

当我使用PHP创建图像时,它不能正确显示UTF-8字符。

$imgPath = 'uplatnica1.jpg';
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 000, 000, 000);

$string = "šđčćž";
$x = 70;
$y = 200;

$fontSize = 3;

imagestring($image, $fontSize, $x, $y, $string, $color);
imagejpeg($image, 'qwe.jpg');

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

read documentation prior asking

总是好的
  

字体

     

可以是1,2, 3 ,4,5用于内置字体 in latin2 encoding (哪里   更高的数字对应更大的字体)或任何你自己的字体   使用imageloadfont()注册的标识符。

和UTF8不是latin2的子集

答案 1 :(得分:0)

您可以查看imagettftext

您的代码将变为:

$imgPath = 'uplatnica1.jpg';
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 000, 000, 000);

$string = "šđčćž";
$x = 70;
$y = 200;

$fontSize = 3;
$fontFile = 'verdana.ttf'; // This file must reside on your system

imagettftext($image, $fontSize, 0, $x, $y, $color, $fontFile, $string);
imagejpeg($image, 'qwe.jpg');

不要忘记您的$fontFile必须存在于服务器上并且可以通过代码访问。

相关问题