2
我試圖使用PHP創建一個透明文本框的圖像與最大。 2行文字。盒子寬度固定爲90px;高度根據所包含的文本而變化(同樣,文本可能佔用1到2行):example。PHP:創建圖像框,其高度取決於其包含的文本
我認爲最具挑戰性的部分是如何根據文本長度「自動」設置框高度。也就是說,該腳本應該足夠智能以便:
- 如果長度超過寬度,則將文本(第2行)換行。
- 調整框高度,因爲現在有兩條線。
假設文本總是適合一行和箱體,該腳本可以相當簡單:
<?php
$im = imagecreatetruecolor(90, 22);
$white = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 92, 149, 167);
// Set the background to be blue
imagefilledrectangle($im, 0, 0, 90, 22, $blue);
// Path to our font file
$font = './Arial.ttf';
imagefttext($im, 10, 0, 5, 15, $white, $font, "Barton Hotel");
// Output to browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
也許我是缺乏瞭解邊界框是什麼:http://stackoverflow.com/q/8587301/583539。幫幫我? – moey 2011-12-21 09:07:00
在那裏回答了你的問題 – ariefbayu 2011-12-21 11:05:32