1-5.php

来自「《php程序设计》的配套源码 《php程序设计》的配套源码 《php程序」· PHP 代码 · 共 31 行

PHP
31
字号
<?php
if (isset($_GET['message'])) {
  // load font and image,calculate width of text
  $font = 'times';
  $size = 12;
  $im = ImageCreateFromPNG('button.png');
  $tsize = imagettfbbox($size, 0, $font, $_GET['message']);
  // center
  $dx = abs($tsize[2]-$tsize[0]);
  $dy = abs($tsize[5]-$tsize[3]);
  $x = (imagesx($im)-$dx)/2;
  $y = (imagesy($im)-$dy)/2 + $dy;
  // draw text
  $black = ImageColorAllocate($im, 0, 0, 0);
  ImageTTFText($im, $size, 0, $x, $y, $black, $font, $_GET['message']);
  // return image
  header('Content-type: image/png');
  ImagePNG($im);
  exit;
}
?>
<html>
<head><title>Button Form</title></head>
<body>
<form action="<?= $PHP_SELF ?>" method="GET">
Enter message to appear on button:
<input type="text" name="message" /><br />
<input type="submit" value="Create Button" /></form>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?