[英]PHP UTF-8 questions - If I create a string in PHP… is it in UTF-8?
[英]PHP Image Create with UTF-8 Character
當我使用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');
我怎么解決這個問題?
在詢問之前先閱讀文檔總是很好的
字形
可以是1,2,3,4,5 為拉丁文2編碼內置字體(其中對應於較大的字體更高的數字)或任何與imageloadfont注冊自己的字體標識符()。
並且UTF8不是latin2的子集
您可以簽出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
必須存在於服務器上並且可以被代碼訪問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.