Jump to content

[SOLVED] ImageTTFText paragraph issue


Asperon

Recommended Posts

Is it possible to take text from a POST that is being written to an image using the GD ImageTTFText function and breaking it apart so that it writes like a paragraph. For example if you have "Welcome to the happiest place on earth" typed into the input text box and subinted but the width of the image it is being written too only is wide enough to hold "Welcome to the happiest", is there a function that automatically breaks text in the image to a second line?? or do I have write my own function for that?

Link to comment
https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/
Share on other sites

like this

<?php
$text = "Welcome to the happiest place on earth";

$textArray = explode('|', wordwrap($text,25,'|'));

$y = $firstLinePos;
foreach ($textArray as $txt) 
{
    imagettftext(..... $txt);
    $y += $lineHeight;
}
?>

thank you, though, it seems that I have another problem now, but I"m not sure why.

 

I have some math in my code that aligns my text where I want it, centers it and then indents.

 

The more characters the text is, with the explode and wordwrap, the farther to the right the text shifts.

 

<?php
//$ln1[0] = text
//$ln1[2] = font size

$box = ImageTTFBBox($ln1[2],0,$font,$ln1[0]);

$d = $box[2] - $box[0];

$align = $width/2 + 30 - $d/2;

$textArray = explode('|', wordwrap($ln1[0],25,'|'));

$y = 40;
foreach ($textArray as $txt) 
{
    ImageTTFText($im,$ln1[2],0,$align,$y,$color,$font,$txt);
    $y += $ln1[2] + 3;
}

?>

k, I got it, heres the reslult...thank you all for your help I really appreciate it

 



<?php

$textArray = explode('|', wordwrap($ln1[0],25,'|'));

$y = 40;
foreach ($textArray as $txt) 
{
    
    $box = ImageTTFBBox($ln1[2],0,$font,$txt);

    $d = $box[2] - $box[0];

    $align = $width/2 + 30 - $d/2;

    ImageTTFText($im,$ln1[2],0,$align,$y,$color,$font,$txt);
    $y += $ln1[2] + 3;


}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.