php 文本文字创建生成图片

原创
2016-06-13 11:23:12 1173浏览

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);
?>


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。