一、数据准备
下载字体;
二、示例代码:
<?php
// 标题文本
$title = "我是标题";
// 数据
$data = [
["id" => "ID", "username" => "用户名", "score" => "得分"],
["id" => 1, "username" => "给你最好的我丶", "score" => 92],
["id" => 2, "username" => "抬首轻笑", "score" => 95],
["id" => 3, "username" => "嘉恒帅比等你王者归来", "score" => 74]
];
// TODO::字体路径
$font = dirname(__FILE__) . "/YaHei.Consolas.1.12.ttf";
$font_size = 30;
// 标题长度
$this_title_box = imagettfbbox($font_size, 0, $font, $title);
$title_x_len = $this_title_box[2] - $this_title_box[0];
$title_height = 60;
// 每行高度
$row_hight = $title_height - 10;
$id_x_len = $username_x_len = $score_x_len = 20;
foreach ($data as $key =>