Reputation: 522
i am trying to break a long phrase depending on my skyscraper banner width size which can not afford more than three words, i searched the internet and found a script which break the text by setting the character long for the phrase, here is it.
<?
header("Content-type: image/png");
$string = $_GET['text']. ' Click Here';
$im = imagecreatefrompng("../../images/skyscrapper.png");
$orange = imagecolorallocate($im, 0, 0, 0);
$px = (imagesx($im) - 3.8 * strlen($string)) / 2;
$font = 'verdana.ttf';
// Break it up into pieces 10 characters long
$lines = explode('|', wordwrap($string, 10, '|'));
// Starting Y position
$y = 450;
// Loop through the lines and place them on the image
foreach ($lines as $line)
{
imagestring($im,3, $px, $y, $string, $orange);
// Increment Y so the next line is below the previous line
$y += 23;
}
imagepng($im);
imagedestroy($im);
?>
the problem is the output duplicate the phrase three times instead breaking the text as this screen shot , can someone help to explain whats the problem and what should i do ?
Upvotes: 1
Views: 1279
Reputation: 854
Maybe replace
imagestring($im,3, $px, $y, $string, $orange);
with
imagestring($im,3, $px, $y, $line, $orange);
Upvotes: 1
Reputation: 360662
You're not changing $string
inside your loop. Shouldn't it be:
imagestring($im,3, $px, $y, $line, $orange);
^^^^^
instead?
Upvotes: 5