如何在PHP中编写对角线文本

时间:2014-07-28 11:00:15

标签: php styles

我想从表中导入一些时间戳,我想在图表下对角线写入。我怎么能这样做?

这是我的代码,但不是导入数据。

header("Content-type: image/png");

$img   = imagecreate(100, 75);
$bg    = imagecolorallocate($img, 255, 255, 0);
$black = imagecolorallocate($img, 0, 0, 0);

$roles = array('anoniem', 'ingelogd', 'leerling', 'docent', 'rector');
$left  = 0;
foreach ($roles as $role) {
  imagestring ($img, 2, 0, $left, $role, $black);
  $left+= 15;
}

$img2 = imagerotate($img, 45, $bg);
imagedestroy($img);

imagepng($img2);

1 个答案:

答案 0 :(得分:1)

imagettftext()用于以任何角度将文本写入图像资源。这不是imagestring()的替代品,但它并不难以开始工作。修改你的代码给了我这个:

$img   = imagecreate(100, 75);
$bg    = imagecolorallocate($img, 255, 255, 0);
$black = imagecolorallocate($img, 0, 0, 0);

$roles = array('anoniem', 'ingelogd', 'leerling', 'docent', 'rector');
$left  = 10;
foreach ($roles as $role) {
  imagettftext($img, 10, 45, $left, 50, $black, 'arial.ttf', $role);
  $left+= 15;
}

header("Content-type: image/png");
imagepng($img);

这似乎就是你想要的。

在:

enter image description here

后:

enter image description here