Welcome to WebmasterWorld Guest from 54.147.44.13

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP with created image write text and text pt problem

PHP with created image write text and text pt problem

     
7:43 am on Jun 11, 2013 (gmt 0)

New User

joined:June 11, 2013
posts:7
votes: 0


Hi
I am makin picture with imagecreate than I am showing tobackground with imagecolorallocate and I am printing with imagestring, my problem is ' I can't set this article's height, I wanna set it's height and I wanna to when the line was be full , it will pass to down


pt is punto



echo '<form action="" method="post">
<input type="text" name="text" id="text">
<input type="submit" value="submit">
</form>';
if(isset($_POST['text'])){
$text=$_POST['text'];
$image = imagecreate(300,300);
$background = imagecolorallocate($image, 250, 0, 0);//color
$imagecolor = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 454, 6,5 , "$text", $imagecolor);
imagepng($image,"images/test.png");
sleep(2);// my pc is slow
imagedestroy($image);
}



$text is came to form.the user is determine($text)

[edited by: jatar_k at 2:32 pm (utc) on Jun 11, 2013]
[edit reason] fixed some funky chars [/edit]

2:35 pm on June 11, 2013 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts: 15755
votes: 0


Welcome to WebmasterWorld erkin0007,

I am not 100% sure if what you want

did you want to set an image you create to the background of an article but the article size is unknown?

obviously you can create whatever size you want with imagecreate but you need to have something to compare with.

I am unclear on this

>> when the line was be full , it will pass to down
3:07 pm on June 11, 2013 (gmt 0)

New User

joined:June 11, 2013
posts:7
votes: 0


User will write the article. And it doesn't pass to down because the line is full
3:26 pm on June 11, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2003
posts:904
votes: 5


The GD graphics library does not automatically break up lines of text to fit within the image boundaries. Your script must calculate the number of pixels required by the string you want to draw (the width), where you need to break the string into lines, and the x and y coordinates of each line to be drawn.

For short strings of one or two sentences, a simple calculation is acceptable. You just need to find the width of each character in the font you're using as well as an appropriate line-height, then use explode() to break the string into words. From there you can calculate where to break up the string into separate lines, and draw them on your image.

If you want to draw long strings consisting of several sentences, I would recommend you search Google for "php gd word wrap". You'll find a few examples of how to do this.
2:49 pm on June 12, 2013 (gmt 0)

New User

joined:June 11, 2013
posts:7
votes: 0


so text punto?
how we set to text punto?
i create new font?because i want to characters are big
10:53 pm on June 12, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


The short answer is: you need to know the exact width of each character, then generate a properly word-wrapped string that is shorter than your maximum width.

You can either do this manually, or look into the solution recommended above. There is really no other way around this.
7:52 am on June 13, 2013 (gmt 0)

New User

joined:June 11, 2013
posts:7
votes: 0


thank you