16

imagettftext(); で左から右ではなく、右から左に文字列を書きたい。関数

角度変数がこれを制御することをマニュアルで読みました.0角度は左から右を意味すると書かれているので、180、360を試しましたが、何も起こりません

右から左に書くには、どの角度に置く必要がありますか

ヘブライ文字をサポートする font.ttf でヘブライ語のテキスト文字列を書いています

<?php   
$white = imagecolorallocate($background, 255, 255, 255);
$fontfile = "davidtr.ttf";
$string = "מחלדגכ";
imagettftext($background, 12, 360, 3, 17, $white, $fontfile, $string);

?>

この関数 strrev() も使用しました。

$white = imagecolorallocate($background, 255, 255, 255);
$fontfile = "davidtr.ttf";
$string = strrev("עברית");
//imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
imagettftext($background, 12, 0, 3, 17, $white, $fontfile, $string);

テキストが画像上で台無しになりました 一部の文字は白いボックスです

次に、この関数を使用しました:

function utf8_strrev($str){
   preg_match_all('/./us', $str, $ar);
   return join('',array_reverse($ar[0]));
}

それは私を大いに助けましたが、今では整数も逆になりました

$string = "מחל 65 דגכ";
echo utf8_strrev($string);
//Now string revered but 65 converted to 56

整数ではなくヘブライ文字のみが反転する、より良い解決策を教えてください。

4

4 に答える 4

0

この関数を使用することをお勧めしますhttp://php.net/manual/de/function.imagettfbbox.php

<?php
$white = imagecolorallocate($background, 255, 255, 255);
$fontfile = "davidtr.ttf";
//text how it should be displayed
$string = "מחלדגכ"; //will result in:
                    //  -------------------
                    // |            מחלדגכ|
                    // |                  |
                    // |                  |
                    //  -------------------
$helper = imageTTFBbox(12,0,$fontfile,$string);
imagettftext($background, 12, 0, 15+imagesx($background)-abs($helper[4] - $helper[0]), 17, $white, $fontfile, $string);
?>

基本的に、テキストの幅を計算し、画像の幅を取得し、それらを差し引いて、パディングを追加します (15)。imageTTFBbox と imagettftext が機能するには、テキスト、フォントファイル、フォントサイズ、および角度が同じである必要があることに注意してください。

テキストを逆にする必要がある場合は、 Master_ex による解決策をお勧めします。

コードはまだテストされていません。

于 2015-08-19T21:15:09.883 に答える