2015-06-06 3 views
12

beitreten Ich verwende TIC, um Text in Bilder zu konvertieren.Wie man Urdu Alphabete bei der Konvertierung von Text in Bild in PHP

Ich habe viel nach diesem gesucht, aber es scheint wie Unicode-Problem (Unicodes der ersten medialen und letzten Buchstaben) oder kann Content-Typ als Bild in PNG sein.

Wenn ich ohne Bildkonvertierung mit content type text/html und charset=UTF-8 echo ich bekomme die gewünschte Ausgabe mit Verbindung Urdu Buchstaben.

require_once 'lib/tic.php'; 
$text="زہرہ نور "; 

TIC::factory('C:\Windows\Fonts\Nastalique.ttf') 
->setText($text) 
->setPadding(10) 
->setBgColor('ff0000') 
->setFontColor(0xff, 0xff, 0x00) 
->setFontSize(24)->create(true); 

als

setzen Aussteigen
ز ہ ر ہ ن و ر 
+0

Zehra konnten Sie die Antwort auf dieses Problem finden? Bitte teilen Sie die Lösung, wenn Sie welche haben. – Aqueel

+0

@Aqueel Bitte zögern Sie nicht, die Antwort zu überprüfen. – Trix

Antwort

4

Sie es so machen kann:

$text = "زہرہ نور"; 

// Make it RTL 
preg_match_all('/([^\d]|\d+)/us', $text, $ar); 
$text = join('',array_reverse($ar[0])); 

// Set font 
$font = 'C:\Windows\Fonts\Nastalique.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); 

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

// Add the text 
imagettftext($im, 12, 0, 20, 20, $black, $font, $text); 
imagegif($im); 
imagedestroy($im); 

Wenn nicht für Sie arbeiten, haben Sie die Möglichkeit php-gd-farsi zu verwenden.

Wie

einfach zu verwenden, um die Bibliothek in Ihrem PHP-Verzeichnis zu kopieren. Die Verwendung ist einfach:

include('php-gd-farsi-master/FarsiGD.php'); 
$gd = new FarsiGD(); 

.... 
// then convert your text: 
$tx = $gd->persianText($str, 'fa', 'normal'); 

komplette Code

include('php-gd-farsi-master/FarsiGD.php'); 

$gd = new FarsiGD(); 

// Create a 300x100 image 
$im = imagecreatetruecolor(300, 100); 
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00); 
$black = imagecolorallocate($im, 0x00, 0x00, 0x00); 

// Make the background red 
imagefilledrectangle($im, 0, 0, 299, 99, $red); 

// Path to our ttf font file 
$font_file = './Nastalique.ttf'; 

// Draw the text 'PHP Manual' using font size 13 
$text = imagecreatetruecolor(200, 60); 
imagefilledrectangle($text, 0, 0, 200, 60, $red); 
$str = 'زہرہ نور'; 
$tx = $gd->persianText($str, 'fa', 'normal'); 
imagefttext($text, 24, 10, 10, 50, $black, $font_file,$tx); 
$im = $text; 

// Output image to the browser 
header('Content-Type: image/png'); 

imagepng($im); 
imagedestroy($im); 
+0

Es hat Trix nicht funktioniert. Können Sie Ihre Ausgabe mit diesem Code teilen? – Aqueel

Verwandte Themen