Home >php教程 >php手册 >php 文本文字创建生成图片

php 文本文字创建生成图片

WBOY
WBOYOriginal
2016-06-13 11:23:121488browse

php 文本文字创建生成图片

现在有不少人要生成文本图像。 PHP的GD库允许我们这样做就是这样。这里我们给出一个简单的方法,是把图像网页上使用的电子邮件地址。有人说,这有助于保持电子邮件收割机远,但其光学字符识别这仍然是可能的。

  // show the correct header for the image type
  header("Content-type: image/jpg");

  // an email address in a string
  $string = "email@example.com";

  // some variables to set
  $font  = 4;
  $width  = ImageFontWidth($font) * strlen($string);
  $height = ImageFontHeight($font);

  // lets begin by creating an image
  $im = @imagecreatetruecolor ($width,$height);

  //white background
  $background_color = imagecolorallocate ($im, 255, 255, 255);

  //black text
  $text_color = imagecolorallocate ($im, 0, 0, 0);

  // put it all together
  imagestring ($im, $font, 0, 0,  $string, $text_color);

  // and display
  imagejpeg ($im);
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn