can any one help me on drawing text on image?

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
smart_koy
Forum Newbie
Posts: 4
Joined: Fri Jan 11, 2008 1:52 am

can any one help me on drawing text on image?

Post 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);
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

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

Post by hannnndy »

just try google and php.net site to solve your problem i have seen the sample code in php.net before
smart_koy
Forum Newbie
Posts: 4
Joined: Fri Jan 11, 2008 1:52 am

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

Post 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.
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

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

Post 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);
 
?>
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

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

Post 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);
}
?>
 
smart_koy
Forum Newbie
Posts: 4
Joined: Fri Jan 11, 2008 1:52 am

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

Post 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 9691 times
and this is problem result
button2.png
button2.png (662 Bytes) Viewed 9689 times
i hope u see the different, event it is my khmer language

anyway, thanks you alot
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

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

Post by hannnndy »

is your problem still remaining?
to draw Unicode characters on image?
am I right?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

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

Post 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.
smart_koy
Forum Newbie
Posts: 4
Joined: Fri Jan 11, 2008 1:52 am

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

Post by smart_koy »

yes my problem is still remaining.

Anyway, thanks a lot for your help.
Post Reply