Jump to content

[SOLVED] make text string read from right to left in imagettftext() function


dsaba

Recommended Posts

I want to write a text string from right to left instead of from left to right with the imagettftext (); function

 

I read in teh manual that the angle variable controls this, it says that 0 angle means left to right, so I tried 180, 360 but nothing happens

 

What angle do I need to put it to get it to write it right to left

 

I am writing a hebrew text string with a font.ttf that supports hebrew characters

 

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

?>

 

-thanks for the help!

ok i tried using hebrev() but that only works for displaying the text, when writing it to the image nothing happens

 

so really what is going is that the hebrew text is being written backwards on the image, so in that case i'm okay with writing the hebrew text backwards in teh first place

 

so is there a function in php to take a string and turn it backwards?

 

for example: i want to change "hello" to "olleh"

ok I discovered this function

strrev()

 

so here is my new code:

$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);

 

now the text is screwed up on the image some letters are white boxes

I read that white boxes mean that the font does not support these characters, however i wrote the same string with the same font earlier and there were no white boxes for characters

so obviously something is fuckin' up the string when I run it through the strrev() function

 

how do I fix this?

the problem was that strrev() had problems reversing UTF-8 encoded text strings (like hebrew)

 

so i used this function to reverse it (taken from comments off php.net)

function utf8_strrev($str){

   preg_match_all('/./us', $str, $ar);

   return join('',array_reverse($ar[0]));

}

 

 

I don't quite understand everythign the function does, but hey it works! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.