Welcome to WebmasterWorld Guest from 54.242.134.77

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

     

erkin0007

7:43 am on Jun 11, 2013 (gmt 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]

jatar_k

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

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



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

erkin0007

3:07 pm on Jun 11, 2013 (gmt 0)



User will write the article. And it doesn't pass to down because the line is full

rainborick

3:26 pm on Jun 11, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

erkin0007

2:49 pm on Jun 12, 2013 (gmt 0)



so text punto?
how we set to text punto?
i create new font?because i want to characters are big

DrDoc

10:53 pm on Jun 12, 2013 (gmt 0)

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



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.

erkin0007

7:52 am on Jun 13, 2013 (gmt 0)



thank you
 

Featured Threads

Hot Threads This Week

Hot Threads This Month