-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persian text results in reversed order of lines when using wrap()
#1396
Comments
Since I can't read the language, it's hard for me to debug correctly here. I will gladly accept pull requests that address this issue. For example, I can't tell if the following code block produces correct output. For me it seems correct. use Intervention\Image\ImageManager;
use Intervention\Image\Typography\FontFactory;
$image = ImageManager::gd()
->create(400, 200)
->fill('ddd');
$text = 'من
سبحان قادری
نسب هستم';
$image->text($text, 350, 150, function (FontFactory $font) {
$font->filename('./ArialUnicodeMS.ttf');
$font->size(40);
$font->color('ff5500');
$font->lineHeight(1.6);
$font->wrap(300);
$font->align('right');
}); |
wrap()
سلام به همه دوستان فارسی زبان من با این کد تونستم فنی درستش کنم $lines = explode("\n", wordwrap($text, 70));
|
A 3rd party library such as AR-PHP is needed to convert the UTF-8 characters to the correct glyphs. For example, if you look at this text شما اهل کجا هستيد؟ and compare it with the image below you can see that a library is needed to generate the text correctly: I have used this text because it has a question mark at the end, which in RTL text should of course be at the left of the text. In the image, when the text is wrapped it is wrapped in the wrong direction so that each following line of text is higher than the previous line (which is not correct because Arabic and Persian are still read from top to bottom like Western languages). In my script, if I use this code $text = 'شما اهل کجا هستيد؟';
$text = $Arabic->utf8Glyphs($text);
$lines = explode("\n", wordwrap($text, 20));
$lines = array_reverse($lines);
foreach ($lines as $i => $line) {
$image->text($line, 450, 360 + ($i * 34), function (FontFactory $font) {
$font->filename('./B-Lotus/B Lotus_0.ttf');
$font->size(44);
$font->color('ff5500');
$font->lineHeight(1.6);
//$font->wrap(60);
$font->align('right');
});
} then I get this image: I am not sure if this fixes the problem, but it is something that users could add to their scripts. This assumes that the rendering of the text is still correct and reads correctly? |
Hello, I checked that in Farsi language, it reverses the text when warping
Its correct form should be as below
من
سبحان قادری
نسب هستم
The text was updated successfully, but these errors were encountered: