can any one help me on drawing text on image?
Moderators: onion2k, General Moderators
can any one help me on drawing text on image?
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);
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);
- 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?
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?
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.
a big thanks in advance.
- 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?
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);
?>- 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?
if the top code did not work just use this one it would would properly
just dont worry
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?
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 and this is problem result i hope u see the different, event it is my khmer language
anyway, thanks you alot
This is what it should look like and this is problem result i hope u see the different, event it is my khmer language
anyway, thanks you alot
- 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?
is your problem still remaining?
to draw Unicode characters on image?
am I right?
to draw Unicode characters on image?
am I right?
Re: can any one help me on drawing text on image?
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?
yes my problem is still remaining.
Anyway, thanks a lot for your help.
Anyway, thanks a lot for your help.