
258
|
第
10
章
图片
$font = "c:/wamp64/www/bookcode/chapter_10/IndieFlower.ttf";
$size = isset($_GET['size']) ? $_GET['size'] : 12;
$text = isset($_GET['text']) ? $_GET['text'] : 'some text';
$path = "/tmp/buttons"; //
按钮缓存目录
//
发送缓存的版本
if ($bytes = @filesize("{$path}/button.png")) {
header("Content-Type: image/png");
header("Content-Length: {$bytes}");
readfile("{$path}/button.png");
exit;
}
//
否则就要创建它、缓存它,然后返回它
$image = imagecreatefrompng("button.png");
$black = imagecolorallocate($image, 0, 0, 0);
if ($text) {
//
计算图片的位置
$tsize = imagettfbbox($size, 0, $font, $text);
$dx = abs($tsize[2] - $tsize[0]);
$dy = abs($tsize[5] - $tsize[3]);
$x = (imagesx($image) ...