imagettftext 和阿拉伯语:如何在 RTL 模式下书写? [英] imagettftext and arabic language: how can I write in RTL mode?

查看:18
本文介绍了imagettftext 和阿拉伯语:如何在 RTL 模式下书写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 RTL 模式下写到 imagettftext,因为阿拉伯语是这样的:我不是要还原字母,我的意思是类似 css 的 RTL(方向:rtl),所以对齐标志在右边...我该怎么办?

我的简单代码:

require('static/I18N/Arabic.php');$Arabic = new I18N_Arabic('Glyphs');$font="static/ArabicModern-Light.ttf";$testo=$阿拉伯语->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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆