Page 1 of 1

can any one help me on drawing text on image?

Posted: Fri Jan 11, 2008 2:13 am
by smart_koy
can someone help me on drawing text on image? I tried to draw khmer unicode text to image. It shows not correct. I used to have the rendering problem in .Net. it's ok for GDI but not for GDI+, same problem. it might be similar problem. can someone help me?

this is my php code

$im = imagecreate($i_width, $i_height);
$white = imagecolorallocate ($im, 255, 255, 255);
$black = imagecolorallocate ($im, 0, 0, 0);

ImageFtText($im, $pointsize, 0, 0, 18, $black , $fontfile, $string, array("linespacing" => 1));

imagepng($im,"content.png");
ImageDestroy ($im);

Re: can any one help me on drawing text on image?

Posted: Mon Jan 14, 2008 3:22 am
by hannnndy
just try google and php.net site to solve your problem i have seen the sample code in php.net before

Re: can any one help me on drawing text on image?

Posted: Mon Jan 14, 2008 10:54 pm
by smart_koy
I have tried to get help from google and php.net but i can't find any solution. maybe i'm not so well understand on what happen? Actually, the php function that i use to draw the string for english is ok but for khmer unicode, it's seem problem with rendering like i've ever had in .NET. it really really great if you can guy me what happen or give me the link on what you have ever seen.
a big thanks in advance.

Re: can any one help me on drawing text on image?

Posted: Tue Jan 15, 2008 2:42 am
by hannnndy
just use this simple code and expand it as you want : ;)

Code: Select all

<?php
 
header("Content-type: image/png");
$string = $_GET['text'];
$im     = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
 
?>

Re: can any one help me on drawing text on image?

Posted: Tue Jan 15, 2008 2:47 am
by hannnndy
if the top code did not work just use this one it would would properly
just dont worry

Code: Select all

 
<?php
//Send a generated image to the browser
create_image();
exit();
 
function create_image()
{
    //Let's generate a totally random string using md5
    $md5 = md5(rand(0,999)); 
    //We don't need a 32 character long string so we trim it down to 5 
    $pass = substr($md5, 10, 5); 
 
    //Set the image width and height
    $width = 100;
    $height = 20; 
 
    //Create the image resource 
    $image = ImageCreate($width, $height);  
 
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);
 
    //Make the background black 
    ImageFill($image, 0, 0, $black); 
 
    //Add randomly generated string in white to the image
    ImageString($image, 3, 30, 3, $pass, $white); 
 
    //Throw in some lines to make it a little bit harder for any bots to break 
    ImageRectangle($image,0,0,$width-1,$height-1,$grey); 
    imageline($image, 0, $height/2, $width, $height/2, $grey); 
    imageline($image, $width/2, 0, $width/2, $height, $grey); 
 
    //Tell the browser what kind of file is come in 
    header("Content-Type: image/jpeg"); 
 
    //Output the newly created image in jpeg format 
    ImageJpeg($image);
   
    //Free up resources
    ImageDestroy($image);
}
?>
 

Re: can any one help me on drawing text on image?

Posted: Tue Jan 15, 2008 3:48 am
by smart_koy
A great thanks to you that reply to me very quickly. But i found that you might not understand my problem. I know how to drawing text. It's no problem for english but it's problem with rendering khmer unicode. Let me show you.

This is what it should look like
button1.png
button1.png (344 Bytes) Viewed 9692 times
and this is problem result
button2.png
button2.png (662 Bytes) Viewed 9690 times
i hope u see the different, event it is my khmer language

anyway, thanks you alot

Re: can any one help me on drawing text on image?

Posted: Wed Jan 16, 2008 2:12 am
by hannnndy
is your problem still remaining?
to draw Unicode characters on image?
am I right?

Re: can any one help me on drawing text on image?

Posted: Wed Jan 16, 2008 2:40 am
by onion2k
Looking at the second image I reckon it's treating your string as single bytes rather than multi byte. I've no idea what the fix would be for that.

Re: can any one help me on drawing text on image?

Posted: Wed Jan 16, 2008 3:50 am
by smart_koy
yes my problem is still remaining.

Anyway, thanks a lot for your help.