我正在處理非英語語言,我想將該文本顯示爲圖像,以便即使在不支持此語言的平臺中也能支持它。問題是我能夠以文本格式正確顯示文本,但是涉及到圖像。它根本不顯示圖像。使用php腳本將文本轉換爲圖像
鏈接下載的字體:http://qfs.mobi/f394372或只是搜索Surya.ttf在谷歌
這裏是我的代碼:
代碼文字圖片:
<?php
// Set the content-type
//mb_internal_encoding("UTF-8");
header('Content-Type: image/png');
require_once('seven.php');
// 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 = getData();//'કેમ છો ?';
//echo $text;
// Replace path by your own font path
$font = 'Surya.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);
?>
代碼的getData( ):
<?php
function getData(){
$url = "http://www.sandesh.com/article.aspx?newsid=119068";
//$url = "http://www.sandesh.com/article.aspx?newsid=115627";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
$DOM = new DOMDocument;
$output = mb_convert_encoding($output, 'HTML-ENTITIES', "UTF-8");
@$DOM->loadHTML($output);
$items = $DOM -> getElementById('lblNews');
echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
'http://www.w3.org/TR/html4/loose.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body><span>". $items -> nodeValue ."</span". "<br/></body></html>";
}
?>
做字體的支持非英語字符? – Sergiu
是的,該字體支持非英文字符。看看這個像$ text = getData(); //'કેમછો?';而不是調用getData,你可以硬編碼文本並檢查字體的工作方式。 – VendettaDroid
我已更新與鏈接下載字體的問題。以防萬一你需要它。 – VendettaDroid