imagettftext和阿拉伯语:如何在RTL模式下书写? [英] imagettftext and arabic language: how can I write in RTL mode?
问题描述
我需要以RTL模式写入imagettftext,因为这种原因是阿拉伯语:而且我的意思不是要还原字母,而是要像css一样的RTL(direction:rtl),所以要对齐标志在右边...我该怎么办?
我的简单代码:
require('static/I18N/Arabic.php');$ Arabic =新的I18N_Arabic('Glyphs');$ font ="static/ArabicModern-Light.ttf";$ testo = $ Arabic-> utf8Glyphs($ testo);imagettftext($ im,26,0,560,345,$ textcolor,$ font,"\".$ testo." \");
谢谢!
最终找到并下载
来自维基百科的参考图片:
下面是
除了未正确对齐之外,这是匹配项.
I need to write in RTL mode to imagettftext, 'caus arabic language is in this way: and I don't mean to revert the letters, I mean a css-like RTL (direction:rtl), so aligned-flag on the right... how can I?
My easy code:
require('static/I18N/Arabic.php');
$Arabic = new I18N_Arabic('Glyphs');
$font="static/ArabicModern-Light.ttf";
$testo=$Arabic->utf8Glyphs($testo);
imagettftext($im, 26, 0, 560, 345, $textcolor, $font, "\"".$testo."\"");
Thanks!
After eventually finding and downloading Ar-PHP 4.0 I've updated this answer to use Arabic. Since I don't understand Arabic I've used the text 'العَرَبِيَّة' from the Arabic Wikipedia page.
Source:
<?php
require_once('./Arabic.php');
$iw = 300; // image width.
$ih = 150; // image height.
$size = 40;
$angle = 0;
$font = 'arial';
$text = 'العَرَبِيَّة';
$obj = new I18N_Arabic('Glyphs');
$text = $obj->utf8Glyphs($text);
$box = imagettfbbox($size, $angle, $font, $text);
$tw = abs($box[6] - $box[4]); // text width.
$th = abs($box[7] - $box[1]); // text height.
$im = imagecreatetruecolor($iw, $ih);
imagefill($im, 0, 0, 0x00c0c0c0); // set a grey background.
// left aligned.
imagettftext($im, $size, $angle, 0, $th, 0x00000000, $font, $text);
// centre aligned.
imagettftext($im, $size, $angle, ($iw / 2) - ($tw / 2), $th * 2, 0x00000000, $font, $text);
// right aligned.
imagettftext($im, $size, $angle, $iw - $tw, $th * 3, 0x00000000, $font, $text);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
Result (generated with PHP 7.1):
Reference image from Wikipedia:
Edit: Below is a comparison of the first five lines from the text you linked to in your comment, run through the code I wrote above (obviously with some minor changes to handle multiple lines):
Your original image (cropped) on the left, my generated image on the right.
Aside from not aligning correctly it's a match.
这篇关于imagettftext和阿拉伯语:如何在RTL模式下书写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!