【问题标题】:php gd text break on image图像上的php gd文本中断
【发布时间】:2012-04-16 21:23:12
【问题描述】:

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

<?

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



?>

问题是输出重复了三个短语而不是像这个屏幕截图那样破坏文本 ,有人可以帮忙解释一下是什么问题,我该怎么办?

【问题讨论】:

    标签: php html gd gdi


    【解决方案1】:

    您不会在循环内更改$string。不应该是:

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

    改为?

    【讨论】:

      【解决方案2】:

      可能替换

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

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

      【讨论】:

        猜你喜欢
        • 2014-05-20
        • 2012-05-27
        • 1970-01-01
        • 2016-05-14
        • 2019-03-23
        • 1970-01-01
        • 2017-06-17
        • 2021-07-03
        • 1970-01-01
        相关资源
        最近更新 更多