'Write Persian Or Arabic on Images with Laravel Intervention \Image Package
I Want to write some Persian Or Arabic on an image. I used the Intervention Image Package ---> https://image.intervention.io/v2 for doing that , but the written words generated reversely .
My Code :
$rarticle = Article::first();
$test = storage_path($rarticle->image);
$waterMarkUrl = Image::make(url('admin-theme/assets/media/image/bannerp.png'));
$waterMarkUrl->resize(180,80);
$image = Image::make($test);
// /* insert watermark at bottom-left corner with 5px offset */
// $image->insert($waterMarkUrl, 'bottom-left', 0, 60);
$image->text($rarticle->title, 120, 100, function($font) {
$font->file(base_path('/admin-theme/assets/fonts/yekane.ttf'));
$font->size(40);
$font->color('#4285F4');
$font->align('center');
$font->valign('bottom');
$font->angle(0);
});
$image->save(storage_path($rarticle->image));
and Generated Image :image laravel
Solution 1:[1]
I think you should download Arabic package https://sourceforge.net/projects/i18n-arabic/
and
require('./I18N/Arabic.php');
// Add styled text to image
$TITLE1 = "???? ????? ???? ????? ???? ????? ";
$Arabic = new I18N_Arabic('Glyphs');
$text1 = new \NMC\ImageWithText\Text($Arabic->utf8Glyphs($TITLE1), 2);
$text1->align = 'right';
$text1->color = 'FFFFFF';
$text1->font = dirname(__FILE__) . '/I18N/DroidNaskh-Bold.ttf';
$text1->lineHeight = 36;
$text1->size = 24;
$text1->startX = 0;
$text1->startY = 0;
$image->addText($text1);

Solution 2:[2]
First install package eskandari/persianrender:
composer require eskandari/persianrender
Then use it in your code :
$persian_text_rev = \PersianRender\PersianRender::render('?????');
$persian_text = '';
for ($i = mb_strlen($persian_text_rev); $i>=0; $i--) {
$persian_text .= mb_substr($persian_text_rev, $i, 1);
}
$image->text($persian_text, 120, 100, function($font) {
$font->file(base_path('/admin-theme/assets/fonts/yekane.ttf'));
$font->size(40);
$font->color('#4285F4');
$font->align('center');
$font->valign('bottom');
$font->angle(0);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Meysam M |
| Solution 2 | emamie |
