1

我试图根据我的摩天大楼横幅宽度大小来打破一个长短语,它不能承受超过三个单词,我在互联网上搜索并找到了一个脚本,它通过将字符设置为长的短语来打破文本,这就是它。

<?

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);



?>

问题是输出重复了该短语三次,而不是像此屏幕截图那样破坏了文本文字不断重复 ,有人可以帮助解释问题出在哪里,我该怎么办?

4

2 回答 2

5

你没有改变$string你的循环。不应该是:

imagestring($im,3, $px, $y, $line, $orange);
                            ^^^^^

反而?

于 2012-04-16T21:24:50.520 回答
1

也许更换

imagestring($im,3, $px, $y, $string, $orange);

imagestring($im,3, $px, $y, $line, $orange);
于 2012-04-16T21:30:00.950 回答