2014-06-07 52 views
5

Üzerinde metin bulunan bir görüntü oluşturmak istiyorum, LTR dilleri iyi çalışıyor gibi görünüyor, ancak Arapça çalışırken, sadece, işe yaramadıPHP ile görüntülüğe RTL (Arapça) metin yaz

// Create a 300*300 image 
$im = imagecreate(300, 300); 

// Yellow transparent background and blue text 
$bg = imagecolorallocatealpha($im, 255, 255, 0, 45); 
$textcolor = imagecolorallocate($im, 0, 0, 255); 

// Write an LTR string 
imagestring($im, 5, 250, 100, 'test', $textcolor); 

$font = 'DroidKufi-Regular.ttf'; // specify the fonts file 
$text = "تجربة"; 
// Add the text 
imagettftext($im, 10, 0, 10, 20, $textcolor, $font, $text); 


// set a red text color 
$textcolor = imagecolorallocate($im, 255, 0, 0); 

// strrev doesn't seem to solve the problem 
$text = strrev($text); 
// add the text 
imagettftext($im, 10, 0, 30, 250, $textcolor, $font, $text); 

imagefilledrectangle ($im, 0, 0, 1, 1, $bg); 

// Output the image 
header('Content-type: image/png'); 

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

nasıl kullanılacağı bir örnek //manual/en/function.imagettftext.php#91028) Kabul ediyorum? Veya [bu bir belki?] (Http://stackoverflow.com/questions/2444015/right-align-text-in-an-image-with-imagettftext-php) .. belki de bilmiyorsunuzdur, belki de sadece [bu bir?] (http://forums.phpfreaks.com/topic/44370-solved-make-text-string-read-from-right-to-left-in-imagettftext-function/) – Ohgodwhy

+0

Evet haklısınız ama bence bu bir http://stackoverflow.com/questions/2444015/right-align-text-in-an-image-with-imagettftext-php bana yardımcı olacak, ama ben bir deneyeceğim , hızlı cevap için teşekkürler :) –

+0

Aslında bu çözüm benim sorunumun yakınında değil –

cevap

6

Sonunda bir çözüm buldum: Ben (bazı yorumlarla) sunulan metin kodu

enter image description here

İşte

benim test kodu ile 3 metin dizeleri çizmek ekran görüntüsü feryat bakınız Bu küçük kütüphane olan diğer bazı forumlarhangi yapıyor, o kütüphaneyi

$text = 'ﺔﻴﺑﺮﻌﻟﺍ'; 

ve kullanma: Buna

$text = 'العربية'; 

:ve mükemmel çalıştı edilir, her şey bu dönüştürerek, pratikte, unicode olan sembollerle içine arap harfleri dönüştürme hakkında Bu dönüşüm, bu (kütüphane gibi sonra) böyle çalışacak önceki kodda böylece:

// Create a 300*300 image 
$im = imagecreate(300, 300); 

// Yellow transparent background and blue text 
$bg = imagecolorallocatealpha($im, 255, 255, 0, 45); 
$textcolor = imagecolorallocate($im, 0, 0, 255); 

// Write an LTR string 
imagestring($im, 5, 250, 100, 'test', $textcolor); 

$font = 'DroidKufi-Regular.ttf'; // specify the fonts file 
$text = "تجربة"; 
$text = word2uni($text); 
// Add the text 
imagettftext($im, 10, 0, 10, 20, $textcolor, $font, $text); 


// set a red text color 
$textcolor = imagecolorallocate($im, 255, 0, 0); 

// strrev doesn't seem to solve the problem 
$text = strrev($text); 
// add the text 
imagettftext($im, 10, 0, 30, 250, $textcolor, $font, $text); 

imagefilledrectangle ($im, 0, 0, 1, 1, $bg); 

// Output the image 
header('Content-type: image/png'); 

imagepng($im); 
imagedestroy($im); 

(the main thread)

+1

bağlantı word2uni için kesildi. Ona ihtiyacım var. yardım lütfen. – hosein

+0

@hosein, e-posta yoluyla bana ulaşın, size gönderebilirim –

+0

i e-postanızı stackoverflow içinde bulamıyorum. Lütfen bana e-postanı verin – hosein

0

bu kütüphaneyi buraya

http://www.ar-php.org/Glyphs-example-php-arabic.html

kontrol edebilirsiniz Bunu [çözümü buradan] (http://www.php.net denedim o

require('../I18N/Arabic.php'); 
$Arabic = new I18N_Arabic('Glyphs'); 
$text = 'بسم الله الرحمن الرحيم'; 
$text = $Arabic->utf8Glyphs($text); 
İlgili konular