多行php图像

时间:2011-09-17 16:19:14

标签: php image gd

我想创建一个显示数据库中所有名称的图像。所以我得到了包含所有名称的数组,但是如何使用PHP制作1个图像,在单独的行上显示所有名称?请举个例子。我已经尝试了很多,但它们都没有用。

2 个答案:

答案 0 :(得分:2)

http://sandbox.phpcode.eu/g/cfb6a

// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write the string at the top left
$lines = 1;
for($i = 1;$i < 10; $i++){
   imagestring($im, 5, 5, $lines * 12, "Hello world $i!", $textcolor);
   $lines++;
}

// Output the image
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);

答案 1 :(得分:1)

它应该看起来如下:

// $gd = <GD resource>
// $names = array('X', 'Y', 'Z');
$font_height = 6;
$colour = imagecolorallocate($gd, 0, 0, 0);
for($i = 0, $count = count($name); $i < $count; $i++)
{
   imagestring($gd, 4, 2, $i * $font_height, $names[$i], $colour);
}
相关问题