如何測試塊是否超過圖像大小並將該文本包裝到下一行。不知道我是否甚至用我的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