简体   繁体   English

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

[英]PHP Image Create with UTF-8 Character

When I create an image with PHP, it does not display UTF-8 characters properly. 当我使用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');

How can I solve this problem? 我怎么解决这个问题?

It's always good to read documentation prior asking 在询问之前先阅读文档总是很好的

font 字形

Can be 1, 2, 3 , 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont(). 可以是1,2,3,4,5 为拉丁文2编码内置字体(其中对应于较大的字体更高的数字)或任何与imageloadfont注册自己的字体标识符()。

and UTF8 is not subset of latin2 并且UTF8不是latin2的子集

You could check out imagettftext . 您可以签出imagettftext

Your code will become: 您的代码将变为:

$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');

Don't forget that your $fontFile must exist on the server and be accessible by the code. 不要忘记您的$fontFile必须存在于服务器上并且可以被代码访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM