Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.92k stars 1.5k forks source link

Persian text results in reversed order of lines when using `wrap()` #1396

Open hmssg opened 2 months ago

hmssg commented 2 months ago

Hello, I checked that in Farsi language, it reverses the text when warping

1807641428114306

Its correct form should be as below

من سبحان قادری نسب هستم

olivervogel commented 2 months ago

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');
});

localhost

hmssg commented 2 months ago

سلام به همه دوستان فارسی زبان من با این کد تونستم فنی درستش کنم

$lines = explode("\n", wordwrap($text, 70));

        foreach ($lines as $i => $line) {
            $image->text(PersianRender::render($line), 540, 800 + ($i * 75), function (FontFactory $font){
                $font->filename(base_path('public/font/Peyda-Black.ttf'));
                $font->size(50);
                $font->color('fff');
                $font->align('center');
                $font->valign('middle');
                $font->lineHeight(3);
            });
        }