0

有人可以告诉我如何使用谷歌网络字体来创建文本验证码吗?

<?php
  $img          = imagecreatetruecolor(200, 200);
  $bgColor      = imagecolorallocate($img, 255, 255, 255);
  $netColor     = imagecolorallocate($img, 185, 185, 185);
  $txtColor     = imagecolorallocate($img, 0, 0, 0);
  imagefill($img, 0, 0, $bgColor);
  imagettftext($img, 22, 0, 50 ,45, $txtColor,"Bedizen.ttf","Expert" ); 
  header("Content-type:image/png");
  imagepng($img);
  imagedestroy($img);
?>

正如您从上面的代码中看到的那样,我正在使用字体文件来呈现文本,但是有没有办法导航到一种 Google 免费网络字体?谢谢

4

1 回答 1

1

对于任何偶然发现这个问题的人(就像我一样) - 这是可行的。正如 Marc 评论的那样,您需要从 Google Fonts 下载字体,上传到您的网络服务器并以这种方式包含它。

我需要包含字体的完整路径,例如:

imagettftext($img, 22, 0, 50 ,45, $txtColor,"/path/to/webroot/fonts/Downlo-Bold.ttf","Expert" );
于 2013-09-02T21:01:57.187 回答