如何测试块是否超过图像大小并将该文本包装到下一行。不知道我是否甚至用我的if语句正确地做到这一点。PHP:包装的测试线长度
$text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we-make-it-super-long-with-some-more/ Lorem Ipsum Lorem Ipsum Lorem Ipsum";
$string_chunks = explode(' ', $text);
foreach ($string_chunks as $chunk) {
if($end_x + $chunk > $image_width){
$start_x = 5;
$start_y += 20;
}
$coords = imagettfbbox($fontsize, $angle, $font, $chunk);
$end_x = $coords[0] + $coords[4] + 10;
$color_to_draw = is_a_url($chunk) ? $linkcolor : $black;
imagettftext($im, $fontsize, $angle, $start_x, $start_y, $color_to_draw, $font, $chunk);
$start_x += $end_x;
}
有了这个代码,我得到:
Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem
http://somelongurl.com/then-we-make-it-super-long-with-some-more/
Lorem Ipsum Lorem Ipsum Lorem Ipsum
我想发生的事情是这样的:
Lorem Ipsum Lorem Ipsum Lorem Ipsum
Lorem http://somelongurl.com/then-we
-make-it-super-long-with-some-more/
Lorem Ipsum Lorem Ipsum Lorem Ipsum
我改变了我的问题,以反映我想要的图像包装像。 – tim 2010-08-31 14:37:45